From: Rogan Hamby Date: Wed, 2 Oct 2019 14:36:54 +0000 (-0400) Subject: more defensive tests for messy records X-Git-Url: http://git.equinoxoli.org/?p=migration-tools.git;a=commitdiff_plain;h=68a14805f5f9422b29752864fbb083c6ac09aadf more defensive tests for messy records --- diff --git a/munge_001_003_035.pl b/munge_001_003_035.pl old mode 100644 new mode 100755 index 8dceb7d..46e2352 --- a/munge_001_003_035.pl +++ b/munge_001_003_035.pl @@ -6,11 +6,17 @@ use MARC::File::USMARC; my $file = MARC::File::USMARC->in( $ARGV[0] ); while ( my $marc = $file->next() ) { my @cns = $marc->field('001'); # grabs all of them - my $cn = $marc->field('001')->data(); # grabs the first - $marc->delete_fields(@cns); # deletes all of them + my $cn; + if (@cns) { + $cn = $marc->field('001')->data(); # grabs the first + $marc->delete_fields(@cns); # deletes all of them + } my @sources = $marc->field('003'); # etc - my $source = $marc->field('003')->data(); - $marc->delete_fields(@sources); + my $source; + if (@sources) { + $source = $marc->field('003')->data(); + $marc->delete_fields(@sources); + } my @tags035 = $marc->field('035'); my $tag035 = $marc->field('035'); my $tag035a = defined $tag035 ? $tag035->subfield('a') : undef; @@ -36,4 +42,3 @@ while ( my $marc = $file->next() ) { } $file->close(); undef $file; -