From e3bd7a8c333e5c4bad46def6e70a28a755d07acf Mon Sep 17 00:00:00 2001 From: Shawn Boyette Date: Mon, 10 Nov 2008 18:51:01 +0000 Subject: [PATCH] seems to be working now --- filter_record.ids | 80 ++++++++++++++++++++++------------------------------ 1 files changed, 34 insertions(+), 46 deletions(-) diff --git a/filter_record.ids b/filter_record.ids index 1f2b754..de88ae9 100644 --- a/filter_record.ids +++ b/filter_record.ids @@ -20,16 +20,19 @@ while () { 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'}; +open $M, '<:utf8', $conf->{marcfile} + or die "Can't open marcfile '",$conf->{marcfile},"'\n"; +open $I, '>:utf8', $conf->{'output-import'} + or die "Can't open import file '",$conf->{'output-import'},"'\n"; +open $S, '>:utf8', $conf->{'output-shelved'} + or die "Can't open shelf file '",$conf->{'output-shelve'},"'\n"; while (<$M>) { my $tag = $conf->{tag}; my $sub = $conf->{subfield}; /tag="$tag" ind1=" " ind2=" ">.*?(\d+){incoming}) { + if ($conf->{mode} eq "exclude") { print $S $_ if ($id{$1}); print $I $_ unless ($id{$1});; } else { @@ -58,39 +61,31 @@ sub initialize { binmode(STDIN, ':utf8'); my $rc = GetOptions( $c, - 'incoming', - 'incumbent', + 'mode=s', + 'include', 'tag|t=i', 'subfield|s=s', 'idfile|i=s', 'marcfile|m=s', - 'outputimport|oi=s', - 'outputshelved|os=s', + 'output-import|oi=s', + 'output-shelved|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') + for my $key ('mode', 'idfile', 'marcfile', 'tag', 'subfield', + 'output-import', 'output-shelved') { push @missing, $key unless $c->{$key} } if (@missing) { print "Required option: ", join(', ', @missing), " missing!\n"; show_help(); } - + unless ($c->{mode} eq "include" or $c->{mode} eq "exclude") { + print "Unknown run mode '", $c->{mode}, "'\n"; + show_help(); + } } @@ -103,35 +98,28 @@ Display usage message when things go wrong sub show_help { print <