http://qs321.pair.com?node_id=762634

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.