{
    "mode": "perldoc",
    "parameter": "MARC::File::USMARC",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/MARC%3A%3AFile%3A%3AUSMARC/json",
    "generated": "2026-06-13T11:25:30Z",
    "synopsis": "use MARC::File::USMARC;\nmy $file = MARC::File::USMARC->in( $filename );\nwhile ( my $marc = $file->next() ) {\n# Do something\n}\n$file->close();\nundef $file;",
    "sections": {
        "NAME": {
            "content": "MARC::File::USMARC - USMARC-specific file handling\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use MARC::File::USMARC;\n\nmy $file = MARC::File::USMARC->in( $filename );\n\nwhile ( my $marc = $file->next() ) {\n# Do something\n}\n$file->close();\nundef $file;\n",
            "subsections": []
        },
        "EXPORT": {
            "content": "None.\n",
            "subsections": []
        },
        "METHODS": {
            "content": "decode( $string [, \\&filterfunc ] )\nConstructor for handling data from a USMARC file. This function takes care of all the tag\ndirectory parsing & mangling.\n\nAny warnings or coercions can be checked in the \"warnings()\" function.\n\nThe $filterfunc is an optional reference to a user-supplied function that determines on a\ntag-by-tag basis if you want the tag passed to it to be put into the MARC record. The function\nis passed the tag number and the raw tag data, and must return a boolean. The return of a true\nvalue tells MARC::File::USMARC::decode that the tag should get put into the resulting MARC\nrecord.\n\nFor example, if you only want title and subject tags in your MARC record, try this:\n\nsub filter {\nmy ($tagno,$tagdata) = @;\n\nreturn ($tagno == 245) || ($tagno >= 600 && $tagno <= 699);\n}\n\nmy $marc = MARC::File::USMARC->decode( $string, \\&filter );\n\nWhy would you want to do such a thing? The big reason is that creating fields is\nprocessor-intensive, and if your program is doing read-only data analysis and needs to be as\nfast as possible, you can save time by not creating fields that you'll be ignoring anyway.\n\nAnother possible use is if you're only interested in printing certain tags from the record, then\nyou can filter them when you read from disc and not have to delete unwanted tags yourself.\n\nupdateleader()\nIf any changes get made to the MARC record, the first 5 bytes of the leader (the length) will be\ninvalid. This function updates the leader with the correct length of the record as it would be\nif written out to a file.\n\nbuildtagdirectory()\nFunction for internal use only: Builds the tag directory that gets put in front of the data in a\nMARC record.\n\nReturns two array references, and two lengths: The tag directory, and the data fields\nthemselves, the length of all data (including the Leader that we expect will be added), and the\nsize of the Leader and tag directory.\n\nencode()\nReturns a string of characters suitable for writing out to a USMARC file, including the leader,\ndirectory and all the fields.\n",
            "subsections": []
        },
        "RELATED MODULES": {
            "content": "MARC::Record\n",
            "subsections": []
        },
        "TODO": {
            "content": "Make some sort of autodispatch so that you don't have to explicitly specify the MARC::File::X\nsubclass, sort of like how DBI knows to use DBD::Oracle or DBD::Mysql.\n\nCreate a toggle-able option to check inside the field data for end of field characters.\nPresumably it would be good to have it turned on all the time, but it's nice to be able to opt\nout if you don't want to take the performance hit.\n",
            "subsections": []
        },
        "LICENSE": {
            "content": "This code may be distributed under the same terms as Perl itself.\n\nPlease note that these modules are not products of or supported by the employers of the various\ncontributors to the code.\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Andy Lester, \"<andy@petdance.com>\"\n",
            "subsections": []
        }
    },
    "summary": "MARC::File::USMARC - USMARC-specific file handling",
    "flags": [],
    "examples": [],
    "see_also": []
}