Drieux, Sorry for the curt thank you. You code looks really good.
On Mon, 22 Dec 2003, drieux wrote: > > On Dec 22, 2003, at 4:32 PM, [EMAIL PROTECTED] wrote: > > > I have two text files I would like to open and read at the same time. > > Whats the best way to do this? > > the only problem with your current form, barring > the faux paux of > > while( ($line1 = <TESTFILE>) && ($line2 = <LOGFILE>)) > { > > } > > is what to do with the case of one file being longer than > the other file. > > So you might try the idea of > > my ($line1, $line2 , $flag ); > while ( 1 ) { > $line1 = <TESTFILE>; # read them each > $line2 = <LOGFILE>; never thought of reading two files one line at a time like this, looks so easy once you showed me. > last unless ( $line1 || $line2 ); # if both empty exit loop > # > # otherwise test for which one just finished > # > unless( $line1 ) > { > $flag = 1; > last; > } > unless( $line2 ) > { > $flag = 2; > last > } a much better line check then the "junk" I wrote. > # > # now do the voodo on the two lines > # > chomp($line2); > chomp($line1); > print "$line2 : $line1\n"; > } > # if one needs to know which ended first one > # can deal with that here... > if ( $flag ) > { > print "more lines to read\n"; > print "\tfrom TestFile \n" if ( $flag == 1 ); > print "\tfrom logfile \n" if ( $flag == 2 ); > } else { > print "both ended together\n"; > } > # now one would be safe to close the files > > HTH. > Helps a bunch, Thanks Again to all who helped.. Denis > ciao > drieux > > --- > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>