my ($a,$b); while( $a=<F1>, $b= <F2>, $a or $b) { ... }
reads till the end of the longer file. Changing to and limits to shorter one.
Cheers Rolf
( addicted to the Perl Programming Language)
Since $a and $b are not chomped, no normal input line should ever be false and hence not necessarily tested with defined.
Better take care if you are using special filehandles allowed to return a simple 0 or null strings!!!
safer:
outuse strict; use warnings; use Data::Dump qw/pp/; open my $f1, "<", \ join "\n", 1..2; open my $f2, "<", \ join "\n", 1..5; while( defined (my $a=<$f1>) + defined (my $b=<$f2>) ) { $a .=""; $b .=""; chomp($a,$b); print "$a,$b\n"; }
1,1 2,2 ,3 ,4 ,5
In boolean context: + is like or, * is like and, just w/o short circuit.
In reply to Re: reading two files in parallel
by LanX
in thread reading two files in parallel
by baxy77bax
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |