Jenda Krynicky wrote:
> From: "Dr.Ruud" <[EMAIL PROTECTED]>
>>Ovid schreef:
>>
>>> my $text = do { local $/; <$fh> };
>>There is a problem with this idiom: it uses about twice the memory of
>>this variant:
>>
>> my $text ; { local $/ ; $text = <$fh> }
>>
>>So if your files can be big (related to the amount of memory
>>available), use the latter.
>
> How do you know? it doesn't seem to be the case. I tried to load a
> 2MB file both ways and the memory consumption seemed to be the same
> (plus or minus a few KB).
>
> I tried then to load a 72MB file and the memory consuption was
> 77,532KB with the do{} and 77,452KB without. Not sure why the
> difference, but it's definitely not twice more.
>
> Unless of course I overlooked something.
If you want to use less memory than either:
read $fh, my $text, -s $fh;
John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>