correct header
[migration-tools.git] / spit_tlc_marc_holdings.pl
1 #!/usr/bin/perl
2 use open ':utf8';
3 use MARC::Batch;
4 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
5 use MARC::Field;
6 use Unicode::Normalize;
7
8 my $count = 0;
9
10 binmode(STDOUT, ':utf8');
11 binmode(STDIN, ':utf8');
12
13 print join("\t",
14         "bib id",
15         "collection code",
16         "prefix",
17         "call number",
18         "cutter number",
19         "barcode",
20         "serial year",
21         "volume number",
22         "part subdivision 1",
23         "part subdivision 2",
24         "part subdivision 3",
25         "part subdivision 4",
26         "copy number",
27         "accession number",
28         "price",
29         "condition",
30         "magnetic media",
31         "checkin-in/check-out note"
32 ) . "\n";
33
34 foreach my $argnum ( 0 .. $#ARGV ) {
35
36         print STDERR "Processing " . $ARGV[$argnum] . "\n";
37
38         my $batch = MARC::Batch->new('XML',$ARGV[$argnum]);
39         $batch->strict_off();
40         $batch->warnings_off();
41
42         while ( my $record = $batch->next() ) {
43
44         $count++;
45
46                 print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
47         my $my_903a = $record->field('903')->subfield('a'); # target bib id's here
48         my @tags = $record->field('949');
49         foreach my $tag ( @tags ) {
50             print join("\t",
51                 $my_903a, # bib id
52                 $tag->subfield('a') || '', # collection code
53                 $tag->subfield('b') || '', # prefix
54                 $tag->subfield('c') || '', # call number
55                 $tag->subfield('d') || '', # cutter number
56                 $tag->subfield('g') || '', # barcode
57                 $tag->subfield('h') || '', # serial year
58                 $tag->subfield('i') || '', # volume number
59                 $tag->subfield('j') || '', # part subdivision 1
60                 $tag->subfield('k') || '', # part subdivision 2
61                 $tag->subfield('l') || '', # part subdivision 3
62                 $tag->subfield('m') || '', # part subdivision 4
63                 $tag->subfield('n') || '', # copy number
64                 $tag->subfield('o') || '', # accession number
65                 $tag->subfield('p') || '', # price
66                 $tag->subfield('q') || '', # condition
67                 $tag->subfield('5') || '', # magnetic media 
68                 $tag->subfield('7') || '' # checkin-in/check-out note
69             ) . "\n";
70         }
71
72         }
73         print STDERR "Processed $count records\n";
74 }