Re: Analize Java source file with perl?
- From: krahnj@xxxxxxxxx (John W. Krahn)
- Date: Sat, 28 Oct 2006 13:56:35 -0700
Jenda Krynicky wrote:
From: "Dr.Ruud" <rvtol+news@xxxxxxxxxxxx>
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
.
- References:
- Re: Analize Java source file with perl?
- From: Jenda Krynicky
- Re: Analize Java source file with perl?
- Prev by Date: Re: Analize Java source file with perl?
- Next by Date: Re: How to pass string in command line argument.
- Previous by thread: Re: Analize Java source file with perl?
- Next by thread: Re: Analize Java source file with perl?
- Index(es):
Relevant Pages
|