# MARC::Batch - Perl module for handling files of MARC::Record objects - perldoc - [phpMan]

## NAME
    [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown) - Perl module for handling files of [MARC::Record](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ARecord/markdown) objects

## SYNOPSIS
    [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown) hides all the file handling of files of "[MARC::Record](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ARecord/markdown)"s. "[MARC::Record](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ARecord/markdown)" still does
    the file I/O, but "[MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown)" handles the multiple-file aspects.

        use [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown);

        # If you have weird control fields...
        use [MARC::Field](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AField/markdown);
        [MARC::Field](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AField/markdown)->allow_controlfield_tags('FMT', 'LDX');


        my $batch = [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown)->new( 'USMARC', @files );
        while ( my $marc = $batch->next ) {
            print $marc->subfield(245,"a"), "\n";
        }

## EXPORT
    None. Everything is a class method.

## METHODS
  new( $type, @files )
    Create a "[MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown)" object that will process @files.

    $type must be either "USMARC" or "MicroLIF". If you want to specify "[MARC::File::USMARC](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AUSMARC/markdown)" or
    "[MARC::File::MicroLIF](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AMicroLIF/markdown)", that's OK, too. new() returns a new [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown) object.

    @files can be a list of filenames:

        my $batch = [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown)->new( 'USMARC', 'file1.marc', 'file2.marc' );

    Your @files may also contain filehandles. So if you've got a large file that's gzipped you can
    open a pipe to gzip and pass it in:

        my $fh = [IO::File](https://www.chedong.com/phpMan.php/perldoc/IO%3A%3AFile/markdown)->new( 'gunzip -c marc.dat.gz |' );
        my $batch = [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown)->new( 'USMARC', $fh );

    And you can mix and match if you really want to:

        my $batch = [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown)->new( 'USMARC', $fh, 'file1.marc' );

  next()
    Read the next record from that batch, and return it as a [MARC::Record](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ARecord/markdown) object. If the current
    file is at EOF, close it and open the next one. next() will return "undef" when there is no more
    data to be read from any batch files.

    By default, next() also will return "undef" if an error is encountered while reading from the
    batch. If not checked for this can cause your iteration to terminate prematurely. To alter this
    behavior, see strict_off(). You can retrieve warning messages using the warnings() method.

    Optionally you can pass in a filter function as a subroutine reference if you are only
    interested in particular fields from the record. This can boost performance.

  strict_off()
    If you would like "[MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown)" to continue after it has encountered what it believes to be bad
    MARC data then use this method to turn strict OFF. A call to strict_off() always returns true
    (1).

### strict_off
    to plow through it. For safety, "[MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown)" strict is ON by default.

  strict_on()
    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. As a
    side effect 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 as this will set warnings on your batch object.

### 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

  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

  filename()
    Returns the currently open filename or "undef" if there is not currently a file open on this
    batch object.

## RELATED MODULES
    [MARC::Record](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ARecord/markdown), [MARC::Lint](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ALint/markdown)

## TODO
    None yet. Send me your ideas and needs.

## 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>>"

