8 #use MARC::File::XML ( BinaryEncoding => 'utf-8' );
12 my $conf = {}; # configuration hashref
15 binmode(STDOUT, ':utf8');
16 binmode(STDIN, ':utf8');
18 foreach my $input ( @ARGV ) {
19 print STDERR "Processing $input, starting record id at ",
20 $conf->{'renumber-from'},"\n";
22 my $batch = MARC::Batch->new('XML', $input);
23 while ( my $record = $batch->next ) {
25 my @warnings = $batch->warnings;
26 print STDERR "WARNINGS: Record $count : ",
27 join(":",@warnings), " : continuing...\n"
30 while ($record->field($conf->{tag}))
31 { $record->delete_field( $record->field($conf->{tag}) ) }
32 my $new_id = $conf->{'renumber-from'} + $count - 1;
33 my $new_id_field = MARC::Field->new( $conf->{tag},
36 $conf->{subfield} => $new_id );
37 $record->append_fields($new_id_field);
38 print $record->as_xml;
40 print STDERR "Processed $count records. Last record id at ",
41 ($conf->{'renumber-from'} + $count - 1), "\n";
47 Performs boring script initialization. Handles argument parsing,
56 # set mode on existing filehandles
57 binmode(STDIN, ':utf8');
59 my $rc = GetOptions( $c,
66 show_help() unless $rc;
68 my @keys = keys %{$c};
69 show_help() unless (@ARGV and @keys);
70 for my $key ('renumber-from', 'tag', 'subfield', 'output')
71 { push @missing, $key unless $c->{$key} }
73 print "Required option: ", join(', ', @missing), " missing!\n";
77 show_help() if ($c->{help});
83 Display usage message when things go wrong
89 Usage is: $0 [REQUIRED ARGS] <filelist>
91 --renumber-from=N -rf First id# of new sequence
92 --tag=N -t Which tag to use
93 --subfield=X -s Which subfield to use
94 --output=<file> -o Output filename
96 Any number of input files may be specified; one output file will result.