MARC::Fast(3pm)

πŸ’– MARC::Fast πŸ’–

okay so bestie, welcome to MARC::Fast(3pm) β€” that's the User Contributed Perl Documentation corner of the manual, and honestly? this module ate. it's a very fast implementation of a MARC database reader, and it's about to be your new main character. πŸŽ€


✨ NAME ✨

MARC::Fast β€” very fast implementation of MARC database reader πŸ¦‹


🌸 SYNOPSIS 🌸

okay so the whole vibe is literally this:

  use MARC::Fast;

  my $marc = new MARC::Fast(
        marcdb => 'unimarc.iso',
  );

  foreach my $mfn ( 1 .. $marc->count ) {
        print $marc->to_ascii( $mfn );
  }

and if you want a longer example, one that's got command line options and everything, go peek at dump_fastmarc.pl in scripts. it's giving demo energy. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

so this is the very fast alternative to the MARC and MARC::Record modules. like, speed. that's the whole point. 🏎️✨

and ngl it's also very suitable for random access to MARC records β€” as opposed to doing it sequentially, one after another, like some kind of peasant. random access is the moment. πŸ‘‘


πŸ’… METHODS πŸ’…

πŸ’– new πŸ’–

reads the MARC database. yes queen, it opens it up and everything.

  my $marc = new MARC::Fast(
        marcdb => 'unimarc.iso',
        quiet => 0,
        debug => 0,
        assert => 0,
        hash_filter => sub {
                my ($t, $record_number) = @_;
                $t =~ s/foo/bar/;
                return $t;
        },
  );

πŸ”₯ count πŸ”₯

returns how many records are in the database. the headcount. the roster. the guest list. 🎟️

  print $marc->count;

🌈 fetch 🌈

fetches a record from the database. grabby hands. πŸ™Œ

  my $hash = $marc->fetch(42);
heads up bestie: the first record number is 1. not zero. one. periodt. πŸ’€

πŸŽ€ last_leader πŸŽ€

returns the leader of the last record that got fetched. like, who's in charge of the most recent one. πŸ‘‘

  print $marc->last_leader;

okay so this got added in version 0.08 of this module, so if you actually need it you should write:

  use MARC::Fast 0.08;

just to be sure it's supported. manifesting it into existence, fr fr. ✨

🧚 to_hash 🧚

reads a record with the specified MFN and converts it into a hash. glow-up complete. πŸ’«

  my $hash = $marc->to_hash( $mfn, include_subfields => 1,
        hash_filter => sub { my ($l,$tag) = @_; return $l; }
  );

it's got this ability to convert characters (using hash_filter) from the MARC database before creating the structures β€” which means you can re-map characters or do a quick little fix-up of your data. and listen: if you specify hash_filter in both new and to_hash, then only the one from to_hash gets used. to_hash wins. no debate. πŸ‘‘

this function returns a hash that looks like this:

  '200' => [
             {
               'i1' => '1',
               'i2' => ' '
               'a' => 'Goa',
               'f' => 'Valdo D\'Arienzo',
               'e' => 'tipografie e tipografi nel XVI secolo',
             }
           ],

and this method also creates an additional field 000 with the MFN in it. bonus content, bestie. 🎁

🌟 to_ascii 🌟

  print $marc->to_ascii( 42 );

🫢 UTF-8 ENCODING 🫢

okay so this module does nothing with encoding. nothing at all. it's not its job. but here's the thing: since the MARC format is byte oriented β€” even when you're using UTF-8, which has a variable number of bytes for each character β€” the file gets opened in binary mode.

as a result, all the scalars returned to perl don't have the utf-8 flag. so what do you do? the solution is to use hash_filter and Encode to decode the utf-8 encoding, like this:

  use Encode;

  my $marc = new MARC::Fast(
        marcdb => 'utf8.marc',
        hash_filter => sub {
                Encode::decode( 'utf-8', $_[0] );
        },
  );

this will affect to_hash, but fetch will still return binary representation since it doesn't support hash_filter. so don't come for fetch, it simply cannot. πŸ™ˆ


πŸ‘‘ AUTHOR πŸ‘‘

the icon, the legend, the moment:


this program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay. πŸ’–

the full text of the license can be found in the LICENSE file included with this module. go read it, it's right there. πŸ“œ


🌈 SEE ALSO 🌈

iykyk. πŸ’…


okay that's the whole page bestie, we ate and left no crumbs πŸ“ β€” this was MARC::Fast(3pm) from perl v5.36.0, dated 2023-01-29. go read some MARC records. mwah. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from