On Jan 19, 2007, at 5:53 PM, Bertrand Baesjou wrote:
Thank you very much, this is indeed the solution.
The explanation is that when you process lines this way
foreach my $line (<FH>) { ... }
the readline operator is evaluated in list context and, thus, the
file is slurped into a single list with all the lines. So, first the
file is fully put into memory, and then foreach starts.
In the line-oriented while loop
while (my $line = <FH>) { ... }
you are fetching line by line[*], and so memory is kept under control
(at least as much in control as the length of the lines in that file,
that wouldn't solve the problem if the file was GBs of data in a
single line, you see how it works).
-- fxn
[*] Under the hood there are actually some buffers, but that's the idea.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/