change to the data directly automatically with mig env use
[migration-tools.git] / munge_001_003_035.pl
old mode 100644 (file)
new mode 100755 (executable)
index 8dceb7d..46e2352
@@ -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;
-