MARC::Batch(3pm)
π NAME π
MARC::Batch β bestie, this is a Perl module for handling whole files of MARC::Record objects β¨
(and yes, it's the MARC::Batch(3pm) page from User Contributed Perl Documentation, we're all friends here π«Ά)
πΈ SYNOPSIS πΈ
okay so real talk: MARC::Batch hides literally ALL the file handling for files full of MARC::Records. MARC::Record is still the one doing the actual file I/O, but MARC::Batch is the one juggling the multiple-file drama π
use MARC::Batch;
# If you have weird control fields...
use MARC::Field;
MARC::Field->allow_controlfield_tags('FMT', 'LDX');
my $batch = MARC::Batch->new( 'USMARC', @files );
while ( my $marc = $batch->next ) {
print $marc->subfield(245,"a"), "\n";
}
π EXPORT π
None. Periodt. Everything in here is a class method π«Ά
π₯ METHODS π₯
π« new( $type, @files )
Makes you a MARC::Batch object that's gonna process @files π¦
$type has to be either "USMARC" or "MicroLIF". And if you'd rather say "MARC::File::USMARC" or "MARC::File::MicroLIF", that's totally fine too, no cap. new() hands you back a new MARC::Batch object β¨
@files can just be a list of filenames:
my $batch = MARC::Batch->new( 'USMARC', 'file1.marc', 'file2.marc' );
But your @files can ALSO hold filehandles π so if you've got a big file that's gzipped, you can open a pipe to gzip and pass that in:
my $fh = IO::File->new( 'gunzip -c marc.dat.gz |' );
my $batch = MARC::Batch->new( 'USMARC', $fh );
And bestie you can mix and match if you rly really want to:
my $batch = MARC::Batch->new( 'USMARC', $fh, 'file1.marc' );
π« next()
Reads the next record out of that batch and gives it back to you as a MARC::Record object π If the current file is at EOF, it closes it and opens the next one. next() returns undef when there's no more data to be read from any of the batch files.
By default, next() ALSO returns undef if it runs into an error while reading from the batch π and if you don't check for that, your iteration can terminate prematurely β it's giving silent betrayal, fr fr. To change that behavior, go look at strict_off(). You can grab the warning messages with the warnings() method.
Optionally you can pass in a filter function as a subroutine reference if you're only interested in particular fields from the record π This can boost performance. Slay.
π« strict_off()
If you want MARC::Batch to keep going after it's encountered what it believes is bad MARC data, call this method and strict goes OFF π A call to strict_off() always returns true (1).
strict_off() is lowkey handy when you don't care about the quality of your MARC data and you just want to plow through it. But for safety: MARC::Batch strict is ON by default, no exceptions π
π« strict_on()
Literally the opposite of strict_off(), and the default state. You shouldn't have to use this method unless you've previously used strict_off() and want it back on again. When strict is ON, calls to next() will return undef when an error is encountered while reading MARC data. strict_on() always returns true (1).
π« warnings()
Returns a list of warnings that have accumulated while processing a particular batch file. Side effect alert π¨ the warning buffer will be cleared.
my @warnings = $batch->warnings();
This method is also used internally to set warnings, so you probably don't want to be passing in anything, bc that will set warnings on your batch object π¬
warnings() will return the empty list when there are no warnings π«Ά
π« warnings_off()
Turns off the default behavior of printing warnings to STDERR. However, even with warnings off the messages can still be retrieved using the warnings() method if you wish to check for them π
warnings_off() always returns true (1).
π« warnings_on()
Turns on warnings so that diagnostic information is printed to STDERR π’ This is on by default so you shouldn't have to use it unless you've previously turned off warnings using warnings_off().
warnings_on() always returns true (1).
π« filename()
Returns the currently open filename, or undef if there is not currently a file open on this batch object πΈ
π RELATED MODULES π
MARC::Record, MARC::Lint
β TODO β
None yet. Send me your ideas and needs, bestie β I'm listening π
π LICENSE π
This code may be distributed under the same terms as Perl itself.
Please note that these modules are not products of or supported by the employers of the various contributors to the code.
π AUTHOR π
Andy Lester, "<andy@petdance.com>"
and that's the whole page, we ate and left no crumbs π
this was MARC::Batch(3pm), written up back in 2022-10-13, shipping with perl v5.36.0 β bye bestie, go read some MARC records π¦π
π¦ where this page comes from
- ubuntu noble: libmarc-record-perl 2.0.7-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmarc-record-perl 2.0.7-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmarc-record-perl 2.0.7-3 Β· 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