more better error reporting
[migration-tools.git] / miker-filter_incumbents.pl
1 #!/usr/bin/perl
2
3 use Time::HiRes qw/time/;
4 use MARC::Record;
5 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
6
7 my $idfile = shift;
8 my $marcfile = shift;
9 my $import = shift;
10 my $shelve = shift;
11
12 my %id;
13
14 open F, "<$idfile";
15 while (<F>) {
16         chomp;
17         $id{$_} = 1;
18 }
19
20 close F;
21
22 my $M;
23 open $M, '<:utf8', $marcfile;
24 open $I, '>:utf8', $import;
25 open $S, '>:utf8', $shelve;
26
27 my $starttime = time;
28 my $count = 0;
29 my $icount = 0;
30 my $scount = 0;
31 while (<$M>) {
32
33         /tag="901" ind1=" " ind2=" "><subfield code="a">(\d+)</;
34         if ( $id{$1} ) {
35                 print $I $_;
36                 $icount++;
37         } else {
38                 print $S $_;
39                 $scount++;
40         }
41         $count++;
42
43         unless ($count && $count % 100) {
44                 print STDERR "\r$count\t(shelved: $scount, import: $icount)\t". $count / (time - $starttime);
45         }
46
47 }
48