Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by Marshall (Abbot)
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?
[Lady_Aleena]: It feels a bit nice doing something that needed doing afk. Helps get my mind off of on keyboard problems.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2017-05-25 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?