From e4c9730525013e33452f350abd91a0d347a02779 Mon Sep 17 00:00:00 2001 From: Jason Etheridge Date: Wed, 3 Dec 2008 11:37:49 +0000 Subject: [PATCH] handle control tags --- spit_tag_multiplication.pl | 60 +++++++++++++++++++++++++++++-------------- 1 files changed, 40 insertions(+), 20 deletions(-) diff --git a/spit_tag_multiplication.pl b/spit_tag_multiplication.pl index c1fd7e9..7a8408a 100755 --- a/spit_tag_multiplication.pl +++ b/spit_tag_multiplication.pl @@ -4,11 +4,12 @@ use MARC::File::XML ( BinaryEncoding => 'utf-8' ); #use MARC::Field; use Unicode::Normalize; -my $filename = $ARGV[0]; -my $tag1 = $ARGV[1]; -my $subfield1 = $ARGV[2]; -my $tag2 = $ARGV[3]; -my $subfield2 = $ARGV[4]; +my $filetype = $ARGV[0]; # XML or USMARC +my $filename = $ARGV[1]; +my $tag1 = $ARGV[2]; # use NONE for no subfield, such as in 001 +my $subfield1 = $ARGV[3]; +my $tag2 = $ARGV[4]; +my $subfield2 = $ARGV[5]; die "required arguments: filename tag1 subfield1 tag2 subfield2\n" if (! ($filename && $tag1 && $subfield1 && $tag2 && $subfield2) ); @@ -19,7 +20,7 @@ binmode(STDIN, ':utf8'); print STDERR "Processing $filename\n"; -my $batch = MARC::Batch->new('XML',$filename); $batch->strict_off(); $batch->warnings_off(); +my $batch = MARC::Batch->new($filetype,$filename); $batch->strict_off(); $batch->warnings_off(); while ( my $record = $batch->next() ) { @@ -30,23 +31,42 @@ while ( my $record = $batch->next() ) { my @tags1 = (); if ($record->field($tag1)) { @tags1 = $record->field($tag1); } else { next; } foreach my $f1 ( @tags1 ) { - if ($f1->subfield($subfield1)) { - my @subfields1 = $f1->subfield($subfield1); - foreach my $s1 ( @subfields1 ) { - #*********************************************************************************************************************** - - my @tags2 = (); if ($record->field($tag2)) { @tags2 = $record->field($tag2); } else { next; } - - foreach my $f2 ( @tags2 ) { - if ($f2->subfield($subfield2)) { - my @subfields2 = $f2->subfield($subfield2); - foreach my $s2 ( @subfields2 ) { - print "$s1\t$s2\n"; + if ($subfield1 eq 'NONE' ) { + + #*********************************************************************************************************************** + + my @tags2 = (); if ($record->field($tag2)) { @tags2 = $record->field($tag2); } else { next; } + + foreach my $f2 ( @tags2 ) { + if ($f2->subfield($subfield2)) { + my @subfields2 = $f2->subfield($subfield2); + foreach my $s2 ( @subfields2 ) { + print $f1->as_string() . "\t$s2\n"; + } } } - } - #*********************************************************************************************************************** + #*********************************************************************************************************************** + + } else { + if ($f1->subfield($subfield1)) { + my @subfields1 = $f1->subfield($subfield1); + foreach my $s1 ( @subfields1 ) { + #*********************************************************************************************************************** + + my @tags2 = (); if ($record->field($tag2)) { @tags2 = $record->field($tag2); } else { next; } + + foreach my $f2 ( @tags2 ) { + if ($f2->subfield($subfield2)) { + my @subfields2 = $f2->subfield($subfield2); + foreach my $s2 ( @subfields2 ) { + print "$s1\t$s2\n"; + } + } + } + + #*********************************************************************************************************************** + } } } } -- 1.7.2.5