7 #use MARC::File::XML ( BinaryEncoding => 'utf-8' );
9 # configuration hashref
15 open F, "<", $conf->{idfile};
23 open $M, '<:utf8', $conf->{marcfile}
24 or die "Can't open marcfile '",$conf->{marcfile},"'\n";
25 open $I, '>:utf8', $conf->{'output-import'}
26 or die "Can't open import file '",$conf->{'output-import'},"'\n";
27 open $S, '>:utf8', $conf->{'output-shelved'}
28 or die "Can't open shelf file '",$conf->{'output-shelve'},"'\n";
31 my $tag = $conf->{tag};
32 my $sub = $conf->{subfield};
34 /tag="$tag" ind1=" " ind2=" ">.*?<subfield code="$sub">(\d+)</;
35 if ($conf->{mode} eq "exclude") {
36 print $S $_ if ($id{$1});
37 print $I $_ unless ($id{$1});;
39 print $S $_ unless ($id{$1});
40 print $I $_ if ($id{$1});;
44 unless ($conf->{count} % 100) {
45 print STDERR "\rProcessed: ",$conf->{count};
51 Performs boring script initialization. Handles argument parsing,
60 # set mode on existing filehandles
61 binmode(STDIN, ':utf8');
63 my $rc = GetOptions( $c,
71 'output-shelved|os=s',
74 show_help() unless $rc;
75 show_help() if ($c->{help});
77 my @keys = keys %{$c};
78 for my $key ('mode', 'idfile', 'marcfile', 'tag', 'subfield',
79 'output-import', 'output-shelved')
80 { push @missing, $key unless $c->{$key} }
82 print "Required option: ", join(', ', @missing), " missing!\n";
85 unless ($c->{mode} eq "include" or $c->{mode} eq "exclude") {
86 print "Unknown run mode '", $c->{mode}, "'\n";
94 Display usage message when things go wrong
103 --mode=MODE Runmode to use (exclude, include; usually exclude)
104 --idfile -i File of record ids to use as source for matchpoints
105 --marcfile -m MARCXML source file
106 --tag -t MARC tag to use as matchpoint (903 when matching
107 incoming records, 901 when matching incumbents)
108 --subfield -s Subfield of tag to use ('a' for incoming, 'c'
110 --output-import -oi Output MARCXML file for records to be imported
111 --output-shelved -os Output MARCXML file for records to be ignored
113 If '--mode=exclude' is specified, the record ids in the file specified
114 by -idfile will be used as EXCLUSION data.
116 That is, the given record ids will be treated as records which match
117 incumbent records, are being compressed into existing data, and so
118 WILL NOT be imported. The --output-import file will contain records
119 whose ids DO NOT occur in --idfile; --output-shelve will contain the
120 records which DO occur.
122 If '--mode=include' is specified, the reverse occurs.