stow_record_data uses named captures now instead of oldstyle automagic capture vars...
[migration-tools.git] / marc-cleanup
index b90ff48..f40babb 100755 (executable)
@@ -180,10 +180,13 @@ sub do_automated_cleanups {
 
 sub stow_record_data {
     # get tag data if we're looking at it
-    if ($record[$ptr] =~ m/<datafield tag="(.{3})" ind1="(.)" ind2="(.)"/) {
-        $recmeta{tag}  = $1;
-        $recmeta{ind1} = $2 || '';
-        $recmeta{ind2} = $3 || '';
+    
+    if ($record[$ptr] =~ m/<datafield tag="(?<TAG>.{3})"/) {
+        $recmeta{tag} = $+{TAG};
+        $record[$ptr] =~ m/ind1="(?<IND1>.)"/;
+        $recmeta{ind1} = $+{IND1} || '';
+        $record[$ptr] =~ m/ind2="(?<IND2>.)"/;
+        $recmeta{ind2} = $+{IND2} || '';
         
         unless (defined $recmeta{tag}) {
             message("Autokill record: no detectable tag");
@@ -191,7 +194,8 @@ sub stow_record_data {
         }
 
         # and since we are looking at a tag, see if it's the original id
-        if ($conf->{'original-subfield'} and $1 == $conf->{'original-tag'}) {
+        if ($conf->{'original-subfield'} and
+            $recmeta{tag} == $conf->{'original-tag'}) {
             my $line = $record[$ptr]; my $lptr = $ptr;
             my $osub = $conf->{'original-subfield'};
             $recmeta{oid} = 'NONE';
@@ -199,7 +203,7 @@ sub stow_record_data {
             until ($line =~ m|</record>|) {
                 $lptr++;
                 $line = $record[$lptr];
-                $recmeta{oid} = $1
+                $recmeta{oid} = $+{TAG}
                   if ($line =~ /<subfield code="$osub">(.+?)</);
             }
         }
@@ -263,7 +267,7 @@ sub buildrecord {
     my $l = '';
     $l = <MARC> while (defined $l and $l !~ /<record>/);
     return $l unless defined $l;
-    @record = ($l);
+    @record = ();
     %recmeta = ();
     $conf->{ricount}++;
 
@@ -323,8 +327,8 @@ sub write_record {
         $conf->{'renumber-from'}++;
     }
 
-    # scrub newlines
-    unless ($conf->{nocollapse})
+    # scrub newlines (unless told not to or writing exception record)
+    unless ($conf->{nocollapse} or $FH eq $EXMARC)
       { s/\n// for (@record) }
 
     # write to old->new map file if needed
@@ -351,7 +355,7 @@ sub print_fullcontext {
     print $OUT $conf->{editmsg},"\n";
     print $OUT "\r    Tag:",$recmeta{tag}, " Ind1:'",
       $recmeta{ind1},"' Ind2:'", $recmeta{ind2}, "'";
-    print $OUT " @ ", $conf->{ricount}, "/", $conf->{rocount} + 1,"\n";
+    print $OUT " @ ", $conf->{ricount}, "/", $conf->{rocount} + 1;
     print_context();
     return 0;
 }
@@ -667,7 +671,7 @@ sub initialize {
     # defaults
     if ($c->{prefix}) {
         $c->{output} = join('.',$c->{prefix},'marc','xml');
-        $c->{exception} = join('.',$c->{prefix},'ex','xml');
+        $c->{exception} = join('.',$c->{prefix},'marc','ex');
     }
     $c->{'renumber-tag'} = 903 unless defined $c->{'renumber-tag'};
     $c->{'renumber-subfield'} = 'a' unless defined $c->{'renumber-subfield'};