1MARC::File::USMARC(3) User Contributed Perl DocumentationMARC::File::USMARC(3)
2
3
4

NAME

6       MARC::File::USMARC - USMARC-specific file handling
7

SYNOPSIS

9           use MARC::File::USMARC;
10
11           my $file = MARC::File::USMARC->in( $filename );
12
13           while ( my $marc = $file->next() ) {
14               # Do something
15           }
16           $file->close();
17           undef $file;
18

EXPORT

20       None.
21

METHODS

23   decode( $string [, \&filter_func ] )
24       Constructor for handling data from a USMARC file.  This function takes
25       care of all the tag directory parsing & mangling.
26
27       Any warnings or coercions can be checked in the warnings() function.
28
29       The $filter_func is an optional reference to a user-supplied function
30       that determines on a tag-by-tag basis if you want the tag passed to it
31       to be put into the MARC record.  The function is passed the tag number
32       and the raw tag data, and must return a boolean.  The return of a true
33       value tells MARC::File::USMARC::decode that the tag should get put into
34       the resulting MARC record.
35
36       For example, if you only want title and subject tags in your MARC
37       record, try this:
38
39           sub filter {
40               my ($tagno,$tagdata) = @_;
41
42               return ($tagno == 245) || ($tagno >= 600 && $tagno <= 699);
43           }
44
45           my $marc = MARC::File::USMARC->decode( $string, \&filter );
46
47       Why would you want to do such a thing?  The big reason is that creating
48       fields is processor-intensive, and if your program is doing read-only
49       data analysis and needs to be as fast as possible, you can save time by
50       not creating fields that you'll be ignoring anyway.
51
52       Another possible use is if you're only interested in printing certain
53       tags from the record, then you can filter them when you read from disc
54       and not have to delete unwanted tags yourself.
55
56   update_leader()
57       If any changes get made to the MARC record, the first 5 bytes of the
58       leader (the length) will be invalid.  This function updates the leader
59       with the correct length of the record as it would be if written out to
60       a file.
61
62   _build_tag_directory()
63       Function for internal use only: Builds the tag directory that gets put
64       in front of the data in a MARC record.
65
66       Returns two array references, and two lengths: The tag directory, and
67       the data fields themselves, the length of all data (including the
68       Leader that we expect will be added), and the size of the Leader and
69       tag directory.
70
71   encode()
72       Returns a string of characters suitable for writing out to a USMARC
73       file, including the leader, directory and all the fields.
74
76       MARC::Record
77

TODO

79       Make some sort of autodispatch so that you don't have to explicitly
80       specify the MARC::File::X subclass, sort of like how DBI knows to use
81       DBD::Oracle or DBD::Mysql.
82
83       Create a toggle-able option to check inside the field data for end of
84       field characters.  Presumably it would be good to have it turned on all
85       the time, but it's nice to be able to opt out if you don't want to take
86       the performance hit.
87

LICENSE

89       This code may be distributed under the same terms as Perl itself.
90
91       Please note that these modules are not products of or supported by the
92       employers of the various contributors to the code.
93

AUTHOR

95       Andy Lester, "<andy@petdance.com>"
96
97
98
99perl v5.38.0                      2023-07-20             MARC::File::USMARC(3)
Impressum