adding compact score
[migration-tools.git] / spit_tag_multiplication.pl
1 #!/usr/bin/perl
2 use MARC::Batch;
3 use MARC::File::XML ( BinaryEncoding => 'utf-8' );
4 #use MARC::Field;
5 use Unicode::Normalize;
6
7 my $filename = $ARGV[0];
8 my $tag1 = $ARGV[1];
9 my $subfield1 = $ARGV[2];
10 my $tag2 = $ARGV[3];
11 my $subfield2 = $ARGV[4];
12
13 die "required arguments: filename tag1 subfield1 tag2 subfield2\n" if (! ($filename && $tag1 && $subfield1 && $tag2 && $subfield2) );
14
15 my $count = 0;
16
17 binmode(STDOUT, ':utf8');
18 binmode(STDIN, ':utf8');
19
20 print STDERR "Processing $filename\n";
21
22 my $batch = MARC::Batch->new('XML',$filename); $batch->strict_off(); $batch->warnings_off();
23
24 while ( my $record = $batch->next() ) {
25
26     $count++;
27
28     print STDERR "WARNINGS: Record $count : " .  join(":",@warnings) . " : continuing...\n" if ( @warnings );
29
30     my @tags1 = (); if ($record->field($tag1)) { @tags1 = $record->field($tag1); } else { next; }
31
32     foreach my $f1 ( @tags1 ) {
33         if ($f1->subfield($subfield1)) {
34             my @subfields1 = $f1->subfield($subfield1);
35             foreach my $s1 ( @subfields1 ) {
36             #***********************************************************************************************************************
37
38                 my @tags2 = (); if ($record->field($tag2)) { @tags2 = $record->field($tag2); } else { next; }
39
40                 foreach my $f2 ( @tags2 ) {
41                     if ($f2->subfield($subfield2)) {
42                         my @subfields2 = $f2->subfield($subfield2);
43                         foreach my $s2 ( @subfields2 ) {
44                             print "$s1\t$s2\n";
45                         }
46                     }
47                 }
48
49             #***********************************************************************************************************************
50             }
51         }
52     }
53 }
54 print STDERR "Processed $count records\n";