Hi folks,

I am misunderstanding something about getline() and while loops.

I get the following error message with the script below:
Can't locate object method "getline" via package "IO::Handle" at
find_uniq_rec_4
..pl line 38, <NEWFILE> chunk 1.


But I can not figure out what is wrong to cause it.


I also suspect there is or will be a conflict between the "while
(<NEWFILE>)" and the getline().


One thing to note:
I need to grab a set of records from NEWFILE before I read OLDFILE, 
I can not process NEWFILE line by line. This set of records varies in
number, 
at least 3 records, probably more, all related in a parent/child structure. 

So I would like to read all of these records into an array, and then use 
the array of records while reading from OLDFILE. Then clear the array and
read 
in the next set of records for comparison to OLDFILE. Records are too long
for grep to handle.

So that is why I am trying to read in multiple records with each pass
through the loop. 
Each file is potentially 150+mb.




#!/usr/bin/perl -wz
use strict;

#--------------------------- resolve filenames
-------------------------------

#my $olddir='/archive';
#my $newdir='/newdata';

#my $oldfile="$olddir".'/'.$_;
#my $newfile="$newdir".'/'.$_;

#-------------------------- declare variables
-------------------------------

my $done = 0;
my $found = 0;
my $new_rec;
my $old_rec;
my $old_rec_key;
my @new_recs = (); # will contain anywhere from 3 to ??
my $ary_ctr = 0;
my $ary_item;
my $ary_rec_key;
my $first_time_thru = 1;
#-------------------------- set up processing
-------------------------------

open (NEWFILE,"</newdata/newdata.dat") || Error('open','file NEWFILE');

open (UNIQFILE,">/newdata/unique.dat") || Error('open','file UNIQFILE');

#------------------------------  main loop -------------------------------

while (<NEWFILE>) {
        @new_recs = ();                 # empty the array
        $ary_ctr = 0;                   # reset array subscript
        $done = 0;                      # set done to not done
        while ( not $done ) {
                @new_recs[$ary_ctr] = $_; # first rec will always be 1
                $_ = NEWFILE->getline();
                $ary_ctr++;                     # increment subscript
                if ( $first_time_thru ) {
                        $first_time_thru = 0;
                } else {
                        if (substr($_, 21, 1) eq '1') {
                        $done = 1;
                        }
                  }
        }

        foreach $ary_item (@new_recs) {
                $ary_rec_key = substr($ary_item, 0, 40);
                open (OLDFILE,"</archive/newdata.dat.timestamp") ||
Error('open'
,'file OLDFILE');
                while (<OLDFILE>) {
                     $old_rec = $_;
                        $old_rec_key = substr($old_rec, 0, 40);
                        if ( $ary_rec_key eq $old_rec_key ) {
                                print "keys match \n";
                                if ($ary_item eq $old_rec ) {
                                        print "recs match \n";
                                        $found = 1;
                                } else {
                                        print "recs do not match \n";
                                        $found = 0;
                                        last;
                                  }
                        } # if end
                } # while end
                print "closing old file \n";
                close (OLDFILE) || Error('close','file OLDFILE');
        } # foreach end

        if ( $found ) {
                foreach $ary_item (@new_recs) {
                print UNIQFILE $ary_item;
                }
        }
}

#------------------ end processing routines
---------------------------------


print "closing new file \n";
close (NEWFILE) || Error('close','file NEWFILE');
print "closing unique file \n";
close (UNIQFILE) || Error('close','file UNIQFILE');

#------------------ error routine(s)
----------------------------------------

sub Error {
print "OLDFILE = /archive/newdata.dat.timestamp \n";
print "NEWFILE = /newdata/newdata.dat \n";
print "cannot $_[0] $_[1]:$! \n";
exit;
}

#------------------ end program --------------------------------------------




Thanks,
Tom Wright


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to