Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://870892]
help
Chatterbox?
[choroba]: I often can't log in to pause. But after it fails for the first time, everything works for the second time.
[cavac]: Ok, thanks for the information
[choroba]: Yes, tried now. Login didn't show the login window at all, timed out, but worked for the second time instantly.
[choroba]: Trying the daemon log...
[choroba]: It seems very slow. But the internet is weird here in Vietnam...
[choroba]: again, stopping it and trying for the second time fixed the problem

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (15)
As of 2017-02-22 09:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?






    Results (325 votes). Check out past polls.