in reply to read from two files with nested while loops
Did you notice the difference? You have to reset the second file-handle ("B") so it starts reading from the very beginning for each step of "A".open A, '1.dat' or die $!; while (my $lineA=<A>){ open B, '2.dat' or die $!; while(my $lineB=<B>){ print $lineA,' ', $lineB; } close B; }
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: read from two files with nested while loops
by dsheroh (Monsignor) on Feb 09, 2011 at 10:28 UTC | |
by diamantis (Beadle) on Feb 09, 2011 at 15:49 UTC | |
|
Re^2: read from two files with nested while loops
by Anonymous Monk on Oct 03, 2014 at 15:25 UTC |