in reply to Large file problem

Your problem lies in your loop. The Angle operator (i.e. <IN>) works in two contexts: list and scalar. In list context, it returns all the lines of the file as a list; In scalar context, it reads and returns one line at a time.

So:

for (<IN>) { # Do some stuff; }

Reads all the files from IN into an array, then processes them one at a time. You want:

while (<IN>) { # Do some stuff; }

In the above, the angle operator is called in scalar context, so only one file line will be read during each loop iteration. That should (I hope) solve your memory and timing problems.

Update: I see that I type too slowly. ;-)

radiantmatrix
require General::Disclaimer;
s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}

Replies are listed 'Best First'.
Re^2: Large file problem
by JohnBrook (Acolyte) on Dec 01, 2004 at 17:42 UTC
    Thanks for the further clarification. Although I know "while" is what I meant (when's Perl going to have DWIM?), it's good to also understand how Perl was responding to exactly what I was telling it to do. All is made clear now. Thank you!
      when's Perl going to have DWIM?

      Lists will be evaluated lazily in Perl 6, which means Perl 6 will DWYM in this circumstance (I think!)

        I heard perl 5.10 will also have this long overdue optimization. foreach (1..1000000) was optimized in perl5005.