Catman...c_each(3pm)

πŸ“¦
version 1.320 Β· 4 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– Catmandu::Fix::Bind::marc_each πŸ’–

okay bestie, welcome to the glow-up of a very specific little Perl manpage from the User Contributed Perl Documentation collection. Yes, we're in the 3pm section, yes it's giving documentation-core, and yes it's actually kind of iconic once you get it. Let's go πŸ¦‹


✨ NAME ✨

Catmandu::Fix::Bind::marc_each β€” a binder that loops over MARC fields. that's it, that's the whole vibe. it loops. over MARC fields. one at a time. slay πŸ’…


🌸 SYNOPSIS 🌸

# Only add the 720 field to the authors when the $e subfield contains a 'promotor'
do marc_each()
    if marc_match("720e","promotor")
        marc_map("720ab",authors.$append)
    end
end

# Delete all the 500 fields
do marc_each()
    if marc_has("500")
        reject()
    end
end

like... look at her. two whole little routines, both wrapped in do marc_each(), both doing extremely specific things. no cap, this is the energy.


πŸŽ€ DESCRIPTION πŸŽ€

so the marc_each binder literally just iterates over each individual MARC field and runs your fixes on each individual field. one field at a time, no skipping, no shortcuts, main character energy for every single field πŸ’–

say your MARC record contains this:

500  $aTest
500  $aTest2$eskip
500  $aTest3

then this Fix right here πŸ‘‡

do marc_each()
    unless marc_match("500e",skip)
        marc_map("500",note.$append)
    end
end

will copy all the 500 fields over to the note field... except for the 500 fields that have a subfield $e equal to "skip". bye to those ones, they don't get invited 🫢

and the result is literally:

note: [Test,Test3]

see? Test2 got left out because she had $e = skip. the binder said "not today" and honestly? respect.


⭐ CONFIGURATION ⭐

🌈 var

ok so var is an optional loop variable, and when you use it, it holds a HASH stuffed with MARC field info. here's everything inside:

tag        - The names of the MARC field
ind1       - The value of the first indicator
ind2       - The value of the second indicator
subfields  - An array of subfield items. Each subfield item is a
             hash of the subfield code and subfield value

so if you've got this MARC field:

500[1, ] $aTest$bRest

then your loop variable is gonna look like:

tag: 500
ind1: 1
ind2: ' '
subfields:
    - a : Test
    - b : Rest

lowkey gorgeous. highkey useful. and the loop variables let you have extra control over how the MARC fields get processed β€” like, you're not just along for the ride anymore, you're driving πŸš—βœ¨

do marc_each(var:this)
  # Set the indicator1 of all MARC 500 field to the value "3"
  if all_match(this.tag,500)
    set_field(tag.ind1,3)
    # Store the result in the MARC file
    marc_remove(500)
    marc_paste(this)
  end
end
note bestie: that example uses var:this, so the loop variable is named this, and inside the block you're reading this.tag and pasting this back with marc_paste(this). copy it exactly, don't get creative with the names unless you rename it everywhere πŸ’€

🧚 SEE ALSO 🧚

  • Catmandu::Fix::Bind

and that's the whole page, no filler, no fluff, every single detail preserved like the little treasure it is πŸ‘‘

signing off with the receipts: this was perl v5.38.2, dated 2024-08-03, filed under Catman...c_each(3pm) in the User Contributed Perl Documentation. periodt πŸ’…πŸ’–

πŸ“¦ where this page comes from