-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmunge_001_003_035.pl
More file actions
executable file
·44 lines (41 loc) · 1.15 KB
/
munge_001_003_035.pl
File metadata and controls
executable file
·44 lines (41 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl -w
use strict;
use MARC::File::USMARC;
my $file = MARC::File::USMARC->in( $ARGV[0] );
while ( my $marc = $file->next() ) {
my @cns = $marc->field('001'); # grabs all of them
my $cn;
if (@cns) {
$cn = $marc->field('001')->data(); # grabs the first
$marc->delete_fields(@cns); # deletes all of them
}
my @sources = $marc->field('003'); # etc
my $source;
if (@sources) {
$source = $marc->field('003')->data();
$marc->delete_fields(@sources);
}
my @tags035 = $marc->field('035');
my $tag035 = $marc->field('035');
my $tag035a = defined $tag035 ? $tag035->subfield('a') : undef;
$marc->delete_fields(@tags035);
if (defined $cn) {
my @arr = (
'035','','','a'
);
if (defined $source) {
push @arr, "($source) $cn";
} else {
push @arr, "$cn";
}
if (defined $tag035a) {
push @arr, 'z';
push @arr, $tag035a;
}
my $new035 = MARC::Field->new(@arr);
$marc->insert_fields_ordered($new035);
}
print $marc->as_usmarc();
}
$file->close();
undef $file;