track failed (evel fail) records
[migration-tools.git] / spit_marc_903a_001.pl
1 #!/usr/bin/perl
2 use MARC::Batch;
3 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
4 use MARC::Field;
5 use Unicode::Normalize;
6
7 my $count = 0;
8
9 binmode(STDOUT, ':utf8');
10 binmode(STDIN, ':utf8');
11
12 foreach my $argnum ( 0 .. $#ARGV ) {
13
14         print STDERR "Processing " . $ARGV[$argnum] . "\n";
15
16     my $M;
17     open $M, '<:utf8', $ARGV[$argnum];
18     my $batch = MARC::Batch->new('XML',$M);
19
20         $batch->strict_off();
21         $batch->warnings_off();
22
23         while ( my $record = $batch->next() ) {
24
25         $count++;
26
27                 print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
28
29         my @my001 = $record->field('001');
30         if (scalar(@my001) == 0 || scalar(@my001) > 1) { die "Wrong number of 001 tags for record $count\n"; }
31         my @my903 = $record->field('903');
32         if (scalar(@my903) == 0 || scalar(@my903) > 1) { die "Wrong number of 903 tags for record $count\n"; }
33         print $my903[0]->subfield('a') . "\t" . $my001[0]->as_string() . "\n"
34         }
35         print STDERR "Processed $count records\n";
36 }