utf8 pragma
[migration-tools.git] / spit_unicorn_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     "library",
16     "barcode",
17     "current location",
18     "home location",
19     "call number",
20     "item type",
21     "acq date",
22     "price",
23     "circulate flag",
24     "total charges",
25     "cat1",
26     "cat2"
27 ) . "\n";
28
29 foreach my $argnum ( 0 .. $#ARGV ) {
30
31         print STDERR "Processing " . $ARGV[$argnum] . "\n";
32
33         my $batch = MARC::Batch->new('XML',$ARGV[$argnum]);
34         $batch->strict_off();
35         $batch->warnings_off();
36
37         while ( my $record = $batch->next() ) {
38
39         $count++;
40
41                 print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
42         my $my_903a = $record->field('903')->subfield('a'); # target bib id's here
43         my @tags = $record->field('999');
44         foreach my $tag ( @tags ) {
45             print join("\t",
46                 $my_903a,
47                 $tag->subfield('m') || '', # library
48                 $tag->subfield('i') || '', # barcode
49                 $tag->subfield('k') || '', # current location
50                 $tag->subfield('l') || '', # home location
51                 $tag->subfield('a') || '', # call number
52                 $tag->subfield('t') || '', # item type
53                 $tag->subfield('u') || '', # acq date
54                 $tag->subfield('p') || '', # price
55                 $tag->subfield('r') || '', # circulate flag
56                 $tag->subfield('n') || '', # total charges
57                 $tag->subfield('x') || '', # cat1
58                 $tag->subfield('z') || ''  # cat2
59             ) . "\n";
60         }
61
62         }
63         print STDERR "Processed $count records\n";
64 }