1MARC::Field(3)        User Contributed Perl Documentation       MARC::Field(3)
2
3
4

NAME

6       MARC::Field - Perl extension for handling MARC fields
7

SYNOPSIS

9         use MARC::Field;
10
11         my $field = MARC::Field->new( 245, '1', '0',
12              'a' => 'Raccoons and ripe corn / ',
13              'c' => 'Jim Arnosky.'
14         );
15         $field->add_subfields( "a", "1st ed." );
16

DESCRIPTION

18       Defines MARC fields for use in the MARC::Record module.  I suppose you
19       could use them on their own, but that wouldn't be very interesting.
20

EXPORT

22       None by default.  Any errors are stored in $MARC::Field::ERROR, which
23       $MARC::Record usually bubbles up to $MARC::Record::ERROR.
24

METHODS

26   new()
27       The constructor, which will return a MARC::Field object. Typically you
28       will pass in the tag number, indicator 1, indicator 2, and then a list
29       of any subfield/data pairs. For example:
30
31         my $field = MARC::Field->new(
32              245, '1', '0',
33              'a' => 'Raccoons and ripe corn / ',
34              'c' => 'Jim Arnosky.'
35         );
36
37       Or if you want to add a field < 010 that does not have indicators.
38
39         my $field = MARC::Field->new( '001', ' 14919759' );
40
41   tag()
42       Returns the three digit tag for the field.
43
44   indicator(indno)
45       Returns the specified indicator.  Returns "undef" and sets
46       $MARC::Field::ERROR if the indno is not 1 or 2, or if the tag doesn't
47       have indicators.
48
49   is_control_field()
50       Tells whether this field is one of the control tags from 001-009.
51
52   subfield(code)
53       When called in a scalar context returns the text from the first
54       subfield matching the subfield code.
55
56           my $subfield = $field->subfield( 'a' );
57
58       Or if you think there might be more than one you can get all of them by
59       calling in a list context:
60
61           my @subfields = $field->subfield( 'a' );
62
63       If no matching subfields are found, "undef" is returned in a scalar
64       context and an empty list in a list context.
65
66       If the tag is less than an 010, "undef" is returned and
67       $MARC::Field::ERROR is set.
68
69   subfields()
70       Returns all the subfields in the field.  What's returned is a list of
71       list refs, where the inner list is a subfield code and the subfield
72       data.
73
74       For example, this might be the subfields from a 245 field:
75
76               (
77                 [ 'a', 'Perl in a nutshell :' ],
78                 [ 'b', 'A desktop quick reference.' ],
79               )
80
81   data()
82       Returns the data part of the field, if the tag number is less than 10.
83
84   add_subfields(code,text[,code,text ...])
85       Adds subfields to the end of the subfield list.
86
87           $field->add_subfields( 'c' => '1985' );
88
89       Returns the number of subfields added, or "undef" if there was an
90       error.
91
92   delete_subfield()
93       delete_subfield() allows you to remove subfields from a field:
94
95           # delete any subfield a in the field
96           $field->delete_subfield(code => 'a');
97
98           # delete any subfield a or u in the field
99           $field->delete_subfield(code => ['a', 'u']);
100
101       If you want to only delete subfields at a particular position you can
102       use the pos parameter:
103
104           # delete subfield u at the first position
105           $field->delete_subfield(code => 'u', pos => 0);
106
107           # delete subfield u at first or second position
108           $field->delete_subfield(code => 'u', pos => [0,1]);
109
110       You can specify a regex to for only deleting subfields that match:
111
112          # delete any subfield u that matches zombo.com
113          $field->delete_subfield(code => 'u', match => qr/zombo.com/);
114
115   delete_subfields()
116       Delete all subfields with a given subfield code. This is here for
117       backwards compatability, you should use the more flexible
118       delete_subfield().
119
120   update()
121       Allows you to change the values of the field. You can update indicators
122       and subfields like this:
123
124         $field->update( ind2 => '4', a => 'The ballad of Abe Lincoln');
125
126       If you attempt to update a subfield which does not currently exist in
127       the field, then a new subfield will be appended to the field. If you
128       don't like this auto-vivification you must check for the existence of
129       the subfield prior to update.
130
131         if ( $field->subfield( 'a' ) ) {
132           $field->update( 'a' => 'Cryptonomicon' );
133         }
134
135       If you want to update a field that has no indicators or subfields
136       (000-009) just call update() with one argument, the string that you
137       would like to set the field to.
138
139         $field = $record->field( '003' );
140         $field->update('IMchF');
141
142       Note: when doing subfield updates be aware that "update()" will only
143       update the first occurrence. If you need to do anything more
144       complicated you will probably need to create a new field and use
145       "replace_with()".
146
147       Returns the number of items modified.
148
149   replace_with()
150       Allows you to replace an existing field with a new one. You need to
151       pass "replace()" a MARC::Field object to replace the existing field
152       with. For example:
153
154         $field = $record->field('245');
155         my $new_field = new MARC::Field('245','0','4','The ballad of Abe Lincoln.');
156         $field->replace_with($new_field);
157
158       Doesn't return a meaningful or reliable value.
159
160   as_string( [$subfields] )
161       Returns a string of all subfields run together.  A space is added to
162       the result between each subfield.  The tag number and subfield
163       character are not included.
164
165       Subfields appear in the output string in the order in which they occur
166       in the field.
167
168       If $subfields is specified, then only those subfields will be included.
169
170         my $field = MARC::Field->new(
171                       245, '1', '0',
172                               'a' => 'Abraham Lincoln',
173                               'h' => '[videorecording] :',
174                               'b' => 'preserving the union /',
175                               'c' => 'A&E Home Video.'
176                       );
177         print $field->as_string( 'abh' ); # Only those three subfields
178         # prints 'Abraham Lincoln [videorecording] : preserving the union /'.
179
180       Note that subfield h comes before subfield b in the output.
181
182   as_formatted()
183       Returns a pretty string for printing in a MARC dump.
184
185   as_usmarc()
186       Returns a string for putting into a USMARC file.  It's really only
187       useful by "MARC::Record::as_usmarc()".
188
189   clone()
190       Makes a copy of the field.  Note that this is not just the same as
191       saying
192
193           my $newfield = $field;
194
195       since that just makes a copy of the reference.  To get a new object,
196       you must
197
198           my $newfield = $field->clone;
199
200       Returns a MARC::Field record.
201
202   warnings()
203       Returns the warnings that were created when the record was read.  These
204       are things like "Invalid indicators converted to blanks".
205
206       The warnings are items that you might be interested in, or might not.
207       It depends on how stringently you're checking data.  If you're doing
208       some grunt data analysis, you probably don't care.
209

SEE ALSO

211       See the "SEE ALSO" section for MARC::Record.
212

TODO

214       See the "TODO" section for MARC::Record.
215

LICENSE

217       This code may be distributed under the same terms as Perl itself.
218
219       Please note that these modules are not products of or supported by the
220       employers of the various contributors to the code.
221

AUTHOR

223       Andy Lester, "<andy@petdance.com>"
224
225
226
227perl v5.12.0                      2006-07-05                    MARC::Field(3)
Impressum