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