use MARC::Batch;
use Getopt::Long;
#use MARC::Record;
-#use MARC::File::XML ( BinaryEncoding => 'utf-8' );
+use MARC::File::XML ( BinaryEncoding => 'utf-8' );
#use MARC::Field;
+$| = 1;
+
my $count = 0;
my $conf = {}; # configuration hashref
initialize($conf);
-binmode(STDOUT, ':utf8');
binmode(STDIN, ':utf8');
+open RENUMBER, '>', $conf->{output};
+binmode(RENUMBER, ':utf8');
+
foreach my $input ( @ARGV ) {
print STDERR "Processing $input, starting record id at ",
$conf->{'renumber-from'},"\n";
' ',
$conf->{subfield} => $new_id );
$record->append_fields($new_id_field);
- print $record->as_xml;
+ print RENUMBER $record->as_xml;
+ print STDERR "\rLast record: $count";
}
- print STDERR "Processed $count records. Last record id at ",
+ print STDERR "\rProcessed $count records. Last record id at ",
($conf->{'renumber-from'} + $count - 1), "\n";
}
# set mode on existing filehandles
binmode(STDIN, ':utf8');
- # set defaults if told to do so
- if ($c->{incoming}) {
- $c->{tag} = 903;
- $c->{subfield} = 'a';
- $c->{output} = 'incoming.renumbered.marc.xml';
- } elsif ($c->{incumbent}) {
- $c->{tag} = 901;
- $c->{subfield} = 'c';
- $c->{output} = 'incumbent.renumbered.marc.xml';
- }
-
my $rc = GetOptions( $c,
'incoming',
'incumbent',
show_help() unless $rc;
show_help() if ($c->{help});
+ # set defaults if told to do so
+ if ($c->{incoming}) {
+ $c->{tag} = 903 unless defined $c->{tag};
+ $c->{subfield} = 'a' unless defined $c->{subfield};
+ $c->{output} = 'incoming.renumbered.marc.xml'
+ unless defined $c->{output};
+ } elsif ($c->{incumbent}) {
+ $c->{tag} = 901 unless defined $c->{tag};
+ $c->{subfield} = 'c' unless defined $c->{subfield};
+ $c->{output} = 'incumbent.renumbered.marc.xml'
+ unless defined $c->{output};
+ }
+
my @keys = keys %{$c};
show_help() unless (@ARGV and @keys);
for my $key ('renumber-from', 'tag', 'subfield', 'output')