#!/usr/bin/perl use warnings; use strict; use Getopt::Long; #use MARC::Record; #use MARC::File::XML ( BinaryEncoding => 'utf-8' ); # configuration hashref my $conf = {}; initialize($conf); my %id; open F, "<", $conf->{idfile}; while () { chomp; $id{$_} = 1; } close F; my $M; my $I; my $S; open $M, '<:utf8', $conf->{marcfile}; open $I, '>:utf8', $conf->{'output-import'}; open $S, '>:utf8', $conf->{'output-shelve'}; while (<$M>) { my $tag = $conf->{tag}; my $sub = $conf->{subfield}; /tag="$tag" ind1=" " ind2=" ">.*?(\d+){incoming}) { print $S $_ if ($id{$1}); print $I $_ unless ($id{$1});; } else { print $S $_ unless ($id{$1}); print $I $_ if ($id{$1});; } $conf->{count}++; unless ($conf->{count} % 100) { print STDERR "\rProcessed: ",$conf->{count}; } } =head2 initialize Performs boring script initialization. Handles argument parsing, mostly. =cut sub initialize { my ($c) = @_; my @missing = (); # set mode on existing filehandles binmode(STDIN, ':utf8'); my $rc = GetOptions( $c, 'incoming', 'incumbent', 'tag|t=i', 'subfield|s=s', 'idfile|i=s', 'marcfile|m=s', 'outputimport|oi=s', 'outputshelved|os=s', 'help|h', ); show_help() unless $rc; show_help() if ($c->{help}); $c->{'incoming-tag'} = 903; $c->{'incoming-subfield'} = 'a'; $c->{'incumbent-tag'} = 901; $c->{'incumbent-subfield'} = 'c'; my @keys = keys %{$c}; unless ($c->{incoming} or $c->{incumbent}) { print "One of --incoming or --incumbent is required.\n"; show_help(); } if ($c->{incoming} and $c->{incumbent}) { print "Only one of --incoming or --incumbent can be specified.\n"; show_help(); } for my $key ('idfile', 'marcfile', 'output-import', 'output-shelved') { push @missing, $key unless $c->{$key} } if (@missing) { print "Required option: ", join(', ', @missing), " missing!\n"; show_help(); } } =head2 show_help Display usage message when things go wrong =cut sub show_help { print <