1MARC::File::USMARC(3) User Contributed Perl DocumentationMARC::File::USMARC(3)
2
3
4
6 MARC::File::USMARC - USMARC-specific file handling
7
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
20 None.
21
23 decode( $string [, \&filter_func ] )
24
25 Constructor for handling data from a USMARC file. This function takes
26 care of all the tag directory parsing & mangling.
27
28 Any warnings or coercions can be checked in the "warnings()" function.
29
30 The $filter_func is an optional reference to a user-supplied function
31 that determines on a tag-by-tag basis if you want the tag passed to it
32 to be put into the MARC record. The function is passed the tag number
33 and the raw tag data, and must return a boolean. The return of a true
34 value tells MARC::File::USMARC::decode that the tag should get put into
35 the resulting MARC record.
36
37 For example, if you only want title and subject tags in your MARC
38 record, try this:
39
40 sub filter {
41 my ($tagno,$tagdata) = @_;
42
43 return ($tagno == 245) ⎪⎪ ($tagno >= 600 && $tagno <= 699);
44 }
45
46 my $marc = MARC::File::USMARC->decode( $string, \&filter );
47
48 Why would you want to do such a thing? The big reason is that creating
49 fields is processor-intensive, and if your program is doing read-only
50 data analysis and needs to be as fast as possible, you can save time by
51 not creating fields that you'll be ignoring anyway.
52
53 Another possible use is if you're only interested in printing certain
54 tags from the record, then you can filter them when you read from disc
55 and not have to delete unwanted tags yourself.
56
57 update_leader()
58
59 If any changes get made to the MARC record, the first 5 bytes of the
60 leader (the length) will be invalid. This function updates the leader
61 with the correct length of the record as it would be if written out to
62 a file.
63
64 _build_tag_directory()
65
66 Function for internal use only: Builds the tag directory that gets put
67 in front of the data in a MARC record.
68
69 Returns two array references, and two lengths: The tag directory, and
70 the data fields themselves, the length of all data (including the
71 Leader that we expect will be added), and the size of the Leader and
72 tag directory.
73
74 encode()
75
76 Returns a string of characters suitable for writing out to a USMARC
77 file, including the leader, directory and all the fields.
78
80 MARC::Record
81
83 Make some sort of autodispatch so that you don't have to explicitly
84 specify the MARC::File::X subclass, sort of like how DBI knows to use
85 DBD::Oracle or DBD::Mysql.
86
87 Create a toggle-able option to check inside the field data for end of
88 field characters. Presumably it would be good to have it turned on all
89 the time, but it's nice to be able to opt out if you don't want to take
90 the performance hit.
91
93 This code may be distributed under the same terms as Perl itself.
94
95 Please note that these modules are not products of or supported by the
96 employers of the various contributors to the code.
97
99 Andy Lester, "<andy@petdance.com>"
100
101
102
103perl v5.8.8 2005-04-27 MARC::File::USMARC(3)