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

read from two files at once?

by JurgyMan (Initiate)
on May 07, 2009 at 15:24 UTC ( [id://762634]=perlquestion: print w/replies, xml ) Need Help??

JurgyMan has asked for the wisdom of the Perl Monks concerning the following question:

I'm comparing two files and deducing Add/Del/Changes from the comparison. I had been using a hash map to do it, but run out of ram with 1.7G input files!! So now am trying to read each line in a loop... This doesnt appear to be working for me: my($ln) = <CURR>; All examples I see have that in a while loop (and work)... Full Code is here: http://jurgy.net/code/

Replies are listed 'Best First'.
Re: read from two files at once?
by samtregar (Abbot) on May 07, 2009 at 15:29 UTC
    The problem with:

    my ($in) = <CURR>;

    Is that it puts <CURR> in list context. That causes it read all the lines in your file and then put the first one in $in! Instead you want:

    my $in = <CURR>;

    Which will read just one line. Reading from two files should work with something like:

    open FILE1, "<", "file1.txt" or die $!; open FILE2, "<", "file1.txt" or die $!; while (!eof(FILE1) and !eof(FILE2)) { my $line1 = <FILE1>; my $line2 = <FILE2>; # ... }

    -sam

Re: read from two files at once?
by eff_i_g (Curate) on May 07, 2009 at 16:49 UTC
    Is diff, sdiff, or Text::Diff out of the question? Just curious.

Log In?
Username:
Password:

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

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

    No recent polls found