MARC::...utorial(3pm)
π NAME π
okay bestie, welcome to MARC::...utorial β yeah that's the short name, the full glow-up is MARC::MIR::Tutorial(3pm), and it lives in the User Contributed Perl Documentation. It's literally the tutorial for the MARC::MIR DSL. Let's go. π¦
β¨ the DSL β¨
so, to make things more readable and less error prone, we also add a DSL. Every keywords of this DSL works the same way. FIXME : explain. (yes girl, it's literally in the source, we're keeping it π)
also, iso2709_records_of is an helper that stream the records of an ISO2709 formatted file. it's giving streaming queen π
πΈ some examples πΈ
the perfect boilerplate π
the starter pack, the bare minimum, the fit that never misses:
use autodie;
use Modern::Perl;
use Perlude;
use MARC::MIR;
print all the ids of the records π
(assuming the id is in 001, the common case β iykyk)
now { say record_id from_iso2709 } iso2709_records_of "biblio.marc";
or, if you wanna be extra:
marawk { say $ID } "biblio.marc";
remove every 9.. fields π§Ή
not me deleting the 9xx fields, they had to go:
now {
$_ = from_iso2709;
with_fields { @$_ = grep { (tag) !~ /^9/ } @$_ };
print to_iso2709;
} iso2709_records_of "biblio.marc";
every 856$q must be jpeg πΈ
the way this one says every single one, no exceptions, periodt:
now {
$_ = from_iso2709;
map_fields {
tag eq '856' and map_subfields {
(tag) eq 'z' and with_value { $_ = 'jpeg' }
}
}
with_fields { @$_ = grep_fields { (tag) !~ /^9/ } @$_ };
} iso2709_records_of "biblio.marc";
or, shorter, because we love a one-liner:
marawk { map_values { $_ = 'jpeg' } [qw< 856 z >] } "biblio.marc"
collect every 856$z by id π
collecting them all like it's a scavenger hunt, keyed by $ID:
use Modern::Perl;
use YAML;
use MARC::MIR;
my %seen;
marawk {
map_values { push @{ $seen{$ID} }, $_ } [qw< 856 z >]
} "data/*.RAW";
say YAML::Dump \%seen;
π marawk π
# TODO:
yeah. that's it. that's the whole section. the author left us on read π iconic honestly.
lowkey obsessed with this module, highkey still waiting on that TODO. no cap. π
and that's the whole vibe check, bestie β this page came from perl v5.36.0, dated 2023-02-09, so shoutout to the version and the date, they ate and left no crumbs β¨ππ
π¦ where this page comes from
- debian bookworm: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmarc-mir-perl 0.4-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms