removing eval trap altogether
[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 $M;
39     open $M, '<:utf8', $ARGV[$argnum];
40     my $batch = MARC::Batch->new('XML',$M);
41
42         $batch->strict_off();
43         $batch->warnings_off();
44
45         while ( my $record = $batch->next() ) {
46
47         $count++;
48
49                 print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
50         my $my_903a = $record->field('903')->subfield('a'); # target bib id's here
51         my @tags = $record->field('949');
52         foreach my $tag ( @tags ) {
53                         if ($tag->subfield('g')) {
54                                         print join("\t",
55                                                 $my_903a, # bib id
56                                                 $tag->subfield('a') || '', # collection code
57                                                 $tag->subfield('b') || '', # prefix
58                                                 $tag->subfield('c') || '', # call number
59                                                 $tag->subfield('d') || '', # cutter number
60                                                 $tag->subfield('g') || '', # barcode
61                                                 $tag->subfield('h') || '', # serial year
62                                                 $tag->subfield('i') || '', # volume number
63                                                 $tag->subfield('j') || '', # part subdivision 1
64                                                 $tag->subfield('k') || '', # part subdivision 2
65                                                 $tag->subfield('l') || '', # part subdivision 3
66                                                 $tag->subfield('m') || '', # part subdivision 4
67                                                 $tag->subfield('n') || '', # copy number
68                                                 $tag->subfield('o') || '', # accession number
69                                                 $tag->subfield('p') || '', # price
70                                                 $tag->subfield('q') || '', # condition
71                                                 $tag->subfield('5') || '', # magnetic media 
72                                                 $tag->subfield('7') || '' # checkin-in/check-out note
73                                         ) . "\n";
74                         }
75         }
76
77         }
78         print STDERR "Processed $count records\n";
79 }