Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

RE: Merging files

by chromatic (Archbishop)
on Aug 27, 2000 at 08:34 UTC ( [id://29857]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://29857]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-25 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found