# man > MARC::File(3pm)

## NAME
    [MARC::File](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile/markdown) - Base class for files of MARC records

## SYNOPSIS
        use [MARC::File::USMARC](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AUSMARC/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 $file = [MARC::File::USMARC](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AUSMARC/markdown)->in( $filename );

        while ( my $marc = $file->next() ) {
            # Do something
        }
        $file->close();
        undef $file;

## EXPORT
    None.

## METHODS
  in()
    Opens a file for import. Ordinarily you will use "[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)"
    to do this.

        my $file = [MARC::File::USMARC](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AUSMARC/markdown)->in( 'file.marc' );

    Returns a "[MARC::File](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile/markdown)" object, or "undef" on failure. If you encountered an error the error
    message will be stored in $[MARC::File::ERROR](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AERROR/markdown).

    Optionally you can also pass in a filehandle, and "[MARC::File](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile/markdown)". will "do the right thing".

        my $handle = [IO::File](https://www.chedong.com/phpMan.php/perldoc/IO%3A%3AFile/markdown)->new( 'gunzip -c file.marc.gz |' );
        my $file = [MARC::File::USMARC](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AUSMARC/markdown)->in( $handle );

  next( [\&filter_func] )
    Reads the next record from the file handle passed in.

    The $filter_func is a reference to a filtering function. Currently, only USMARC records support
    this. See [MARC::File::USMARC](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AUSMARC/markdown)'s "decode()" function for details.

    Returns a [MARC::Record](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ARecord/markdown) reference, or "undef" on error.

  skip()
    Skips over the next record in the file. Same as "next()", without the overhead of parsing a
    record you're going to throw away anyway.

    Returns 1 or undef.

  warnings()
    Simlilar to the methods in [MARC::Record](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ARecord/markdown) and [MARC::Batch](https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3ABatch/markdown), "warnings()" will return any warnings
    that have accumulated while processing this file; and as a side-effect will clear the warnings
    buffer.

  close()
    Closes the file, both from the object's point of view, and the actual file.

  write()
    Writes a record to the output file. This method must be overridden in your subclass.

  decode()
    Decodes a record into a USMARC format. This method must be overridden in your subclass.

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

## TODO
    *   "out()" method

        We only handle files for input right now.

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

