2 # -*- coding: iso-8859-15 -*-
3 ###############################################################################
6 =item B<prepbibs> --file foo.mrc
8 Converts a MARC binary file internally to XML and changes 999 subfields to
9 998s with a special subfield z with a value of 'converted 999 field' added for
15 ###############################################################################
22 HOME PGHOST PGPORT PGUSER PGDATABASE MIGSCHEMA
23 MIGBASEWORKDIR MIGBASEGITDIR MIGGITDIR MIGWORKDIR
35 use List::MoreUtils qw(uniq);
37 my $mig_bin = "$FindBin::Bin/";
38 use lib "$FindBin::Bin/";
40 use open ':encoding(utf8)';
42 binmode STDOUT, ":utf8";
44 pod2usage(-verbose => 2) if defined $ARGV[0] && $ARGV[0] eq '--help';
45 pod2usage(-verbose => 1) if ! $ARGV[1];
54 my $outfile = $infile . '.prepped_xml';
55 my $errorfile = $infile . '.errors_xml';
57 open my $outfh, '>:utf8', $outfile or die "Can't open output file $!\n";
58 open my $errorfh, '>:utf8', $errorfile or die "Can't open error file $!\n";
60 my $filetype = `file $infile`;
62 if ($filetype =~ m/MARC21/) {
63 $batch = MARC::Batch->new( 'USMARC', $infile );
65 $batch = MARC::Batch->new( 'XML', $infile );
69 while ( eval {$record = $batch->next()} or do { if ($@) { print $errorfh $record->as_xml(); next; } } ) {
71 print "Processed: $i\n" if ($i % 100) == 0;
72 my @nnn = $record->field('999');
73 foreach my $n (@nnn) {
75 $n->add_subfields( 'z' => 'converted 999 field' );
77 print $outfh $record->as_xml(),"\n";
88 print STDERR "$0: $msg", "\n";