in reply to Re: What is faster?
in thread What is faster?

The theory is right, the application less so.

The <OUTPUT> construct immediately sucks the whole file into memory. To get the full space savings that you describe (not using variables will get you some...), you need to do something like this:

open(OUTPUT, "$script |") or die "Cannot run '$script': $!"; my @output; while (<OUTPUT>) { push @output, $_ if /EXPRESSION/; }
With the emphasis on creative laziness that they keep on talking about for Perl 6, it is possible that Perl 6 will automatically save memory for you with your construct. It is definite that Ruby does. But with Perl 5, you need to write things out longhand.

UPDATE Zaxo pointed out that I didn't close the diamond properly. Fixed.

Replies are listed 'Best First'.
Re: Re: Re: What is faster?
by BrowserUk (Patriarch) on Jun 03, 2003 at 06:00 UTC

    Good point, crap implementation. Thanks for pointing it out.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller