#!/usr/bin/perl
+use strict;
+use warnings;
+
use open ':utf8';
use MARC::Batch;
use MARC::File::XML ( BinaryEncoding => 'utf-8' );
use Unicode::Normalize;
my $count = 0;
-my $which = $ARGV[0];
-my $id_tag = $ARGV[1]; my $id_subfield = $ARGV[2];
+my $which = shift;
+my $id_tag = shift;
+my $id_subfield = shift;
binmode(STDOUT, ':utf8');
binmode(STDIN, ':utf8');
-my $M;
-
-foreach $argnum ( 3 .. $#ARGV ) {
+for my $file (@ARGV) {
- print STDERR "Processing " . $ARGV[$argnum] . "\n";
+ print STDERR "Processing $file\n";
- open $M, '<:utf8', $ARGV[$argnum];
+ open my $M, '<:utf8', $file;
my $batch = MARC::Batch->new('XML',$M);
$batch->strict_off();
next;
}
$id = $id->as_string($id_subfield);
- print STDERR "WARNINGS: Record id " . $id . " : " .
- join(":",@warnings) . " : continuing...\n" if ( @warnings );
my $leader = $record->leader();
my $record_type = substr($leader,6,1);
my $desc = $record->field('300');
if ( $desc ) { $desc = $desc->subfield('a'); }
my $pages;
- if ($desc =~ /(\d+)/) { $pages = $1; }
+ if (defined $desc and $desc =~ /(\d+)/) { $pages = $1; }
my $my_260 = $record->field('260');
my $publisher = $my_260->subfield('b') if ( $my_260 );
my $pubyear = $my_260->subfield('c') if ( $my_260 );
if ( $edition ) { $edition = $edition->subfield('a'); }
# NORMALIZE
- if ($record_type == ' ') { $record_type = 'a'; }
+ $record_type = 'a' if ($record_type eq ' ');
if ($title) {
$title = NFD($title); $title =~ s/[\x{80}-\x{ffff}]//go;
$title = lc($title);