in reply to Loop through 2 files in parallel
You definitely don't want to nest your file-reading loops. Instead, try something like this (untested):
Caution: Contents may have been coded under pressure.
while (my $w1 = <FILE> and my $w2 = <FILE2>) { if ($w1 lt $w2) { print "\n"; $w1 = <FILE>; } elsif ($w1 gt $wt) { print "\n"; $w2 = <FILE2>; } else { print $w1; } } # Leftover lines in either file? print "\n" while <FILE>; print "\n" while <FILE2>;
Caution: Contents may have been coded under pressure.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Loop through 2 files in parallel
by rwitmer (Initiate) on Nov 10, 2010 at 21:07 UTC | |
by happy.barney (Friar) on Nov 11, 2010 at 07:50 UTC |
In Section
Seekers of Perl Wisdom