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;

(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