in reply to Merging files

That's pretty compact as is. Here's one possibility, though (untested):
while ($line1 = <FILE1> && $line2 = <FILE2>) { print RESULT $line1, $line2; }
The while loop does the equivalent of your defined check.

Update: merlyn points out that && is too high on the precedence scale to work. Use and instead. Also, this code is likely to fail if you hit a line of '0', as the loop actually does a truth-test. Thanks!

Replies are listed 'Best First'.
RE: RE: Merging files
by gumpu (Friar) on Aug 27, 2000 at 22:45 UTC

    I think it will also fail if one file happens to be longer than the other file. In that case the tail of the longer file won't be printed. This cause of the &&.

    Have Fun