#!/usr/bin/perl use warnings; use strict; use Getopt::Long; # 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} 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+){mode} eq "exclude") { 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, 'mode=s', 'include', 'tag|t=i', 'subfield|s=s', 'idfile|i=s', 'marcfile|m=s', 'output-import|oi=s', 'output-shelved|os=s', 'help|h', ); show_help() unless $rc; show_help() if ($c->{help}); my @keys = keys %{$c}; 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(); } } =head2 show_help Display usage message when things go wrong =cut sub show_help { print <