Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Perl: the Markov chain saw
 
PerlMonks  

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

by Marshall (Prior)
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"; }


Comment on Re^4: Reading two text files parallelly...
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2014-04-19 08:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (478 votes), past polls