Hi all,

I'm trying to read in two file sets of library records, compare a regex that I find in different lines of each set of records, and then copy one whole line over to the other when a match is found.

To do this, I am trying to use a 3-dimensional array:
[fileset][record][line]

I think that I am reading and pushing the arrays onto the other arrays correctly, but when I'm traversing the arrays to do the conditionals, I am getting uninitialized value warnings, which seems like I'm either not traversing correctly OR I'm not really pushing the data onto the arrays properly.

This is my whole script below.  Does anyone see what I'm doing wrong?

Thanks,
Tim

--
Tim McGeary '99, '06G
Senior Systems Specialist
Lehigh University
610-758-4998
[EMAIL PROTECTED]



use strict;
use warnings;

our $marchead1 = '*** DOCUMENT BOUNDARY ***';
our $marchead2 = 'FORM=MARC';

sub read_records {      # read in whole MARC record and push it to @marc

   my @marc;
   my @record;
   my @line;
   open FILE, $_[0] or die qq(Cannot open file $_[0]\n);
   print "Opening file $_[0]...\n";
   my $index = -1;
   while (<FILE>) {
      chomp;
      #print "Reading in $_\n";
      if ($_ eq $marchead1) {
         if ($index >= 0) {
            push @marc, [ @record ];
            print "Pushing record onto marc array...\n";
            print "Next record....\n\n";
         }
         $index++;
      }
      elsif ($_ eq $marchead2) { next; }
      else {
         @line = ();
         my $field = substr($_, 0, 5);
         my $data = substr($_, 5);
         push @line, [ $field, $data ];
         #print "Splitting line $field\t$data\n";
         next;
      }
      push @record, [ @line ];
   }
   print "Closing file $_[0]...\n";
   close FILE;
   return @marc;
}

my $diss_file = "diss.flat";
my $sirsi_file = "ludiss.flat";

my @proquest = read_records($diss_file);
my @sirsi = read_records($sirsi_file);

my $pdiss_id;
my $s001;
my $sdiss_id;
my $found;

my $p;
my $pl;
my $s;
my $sl;

print "Starting match process... \n";
for $p ( 0 .. $#proquest ) {
$found = 0; # fresh proquest record, therefore no matching Sirsi record found
   for $pl ( 0 .. $#{$proquest[$p]} ) {
      if ($proquest[$p][$pl][0] eq '.001.') {
         $pdiss_id = substr($proquest[$p][$pl][1], 6, 7);
         print "proquest_dissertation ID = $pdiss_id\n"
      }

      for $s ( 0 .. $#sirsi ) {
         for $sl ( 0 .. $#{$sirsi[$s]} ) {
            if ($sirsi[$s][$sl][0] eq '.001.') {
               $s001 = $sirsi[$s][$sl][1];
            }  # end if

            if ($sirsi[$s][$sl][0] eq '.856.') {
               if ($sirsi[$s][$sl][1] =~ /\d{7}/) {
                  $sdiss_id = $1;
                  if ($pdiss_id eq $sdiss_id) {
                     print "Found match!  $pdiss_id = $sdiss_id\n";
                     $proquest[$p][$pl][1] = $s001;
                     $found = 1;
last; # this will skip to the end of the foreach $sl loop
                  } # end if
               }  # end if
            }  # end if
         } # end for $sl
if ($found == 1) { last; } # this will skip to the end of the foreach $s loop
      }  # end for $s
if ($found == 1) { last; } # this will skip to the end of the foreach $pl loop
   }  # end for $pl
}  # end foreach $p

# write @proquest to file

my $pline;
my @pline;

print "Writing edited proquest records to file...\n";
open FILE, ">e-diss.flat" or die qq(Cannot open e-diss.flat);
foreach my $precord (@proquest) {
   print "$marchead1\n";
   print "$marchead2\n";
   foreach $pline (@$precord) {
      print "@$pline\n";
   }
}

close FILE;




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to