Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^4: Reading two text files parallelly...

by Marshall (Monsignor)
on Nov 11, 2010 at 16:48 UTC ( #870892=note: print w/replies, xml ) Need Help??

in reply to Re^3: Reading two text files parallelly...
in thread Reading two text files parallelly...

Sounds like the main problem is to get very clear about what you want this program to do. If you want to just stop when both files are over, or when lines run out of one of them, another possibility is below. The while() takes an expression that evaluates to true/false. Nothing wrong with have more than one condition in an "and" statement. You can use "or" if you want. I don't see the need for anything fancy - try to keep it as easy to understand as possible.
#!/usr/bin/perl -w use strict; open (my $fh1, '<', "testa.txt") or die "cannot open testa"; open (my $fh2, '<', "testb.txt") or die "cannot open testb"; while ( defined (my $test1 = <$fh1>) and defined (my $test2 = <$fh2>) ) { print "both defined\n"; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2016-10-25 22:57 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (330 votes). Check out past polls.