track failed (evel fail) records
[migration-tools.git] / spot_check.pl
1 #!/usr/bin/perl
2 use open ':utf8';
3 use MARC::Batch;
4 use MARC::Record;
5 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
6 use MARC::Field;
7
8 my $count = 0;
9
10 binmode(STDOUT, ':utf8');
11 binmode(STDIN, ':utf8');
12
13 my $M;
14
15 foreach $argnum ( 0 .. $#ARGV ) {
16
17         print STDERR "Processing " . $ARGV[$argnum] . "\n";
18
19         open $M, '<:utf8', $ARGV[$argnum];
20
21         my $batch = MARC::Batch->new('XML',$M);
22         $batch->strict_off();
23         $batch->warnings_off();
24
25     my $last_successful_record;
26
27     eval {
28         while ( my $record = $batch->next() ) {
29
30             $count++; 
31
32             $last_successful_record = $record->as_xml();
33
34             print STDERR "WARNINGS: Record $count : " . join(":",@warnings) . " : continuing...\n" if ( @warnings );
35
36             unless ($count % 1000) {
37                 print STDERR "$count\r"
38             }
39
40         }
41     };
42     print STDERR "Processed $count records.  Last successful record = " . $last_successful_record . "\n";
43     warn $@ if $@;
44 }