diamantis has asked for the wisdom of the Perl Monks concerning the following question:
I expected the following code to read line by line file 1.dat and 2.dat and compare each line of file 1.dat with each line of file 2.dat.
Apparently there is something in the behavior of filehandles that I don't understand as the condition in the first while loop does not evaluate true a second time.open A, '1.dat' or die $!; open B, '2.dat' or die $!; while (my $lineA=<A>){ while(my $lineB=<B>){ print $lineA,' ', $lineB; } }
example files
thank you for any sugestions1.dat ---- 1 2 3 2.dat ---- a b c
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: read from two files with nested while loops
by CountZero (Bishop) on Feb 09, 2011 at 06:57 UTC | |
by dsheroh (Monsignor) on Feb 09, 2011 at 10:28 UTC | |
by diamantis (Beadle) on Feb 09, 2011 at 15:49 UTC | |
by Anonymous Monk on Oct 03, 2014 at 15:25 UTC |