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
In reply to Re: read from two files with nested while loops
by CountZero
in thread read from two files with nested while loops
by diamantis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |