opening a file in perl

Kim Holburn kim.holburn at anu.edu.au
Wed May 1 10:12:39 EST 2002


At 9:58 AM +1000 02/5/1, Nemo - earth native wrote:
>Hi guys, a quick question for the perl guru's around...
>
>I've a small script which opens a file, reads through it looking for
>various information, uses that to calculate some figures, and closes.
>
>Pretty simple stuff.
>
>...except when the file being opened is the better part of 400meg,
>and so I get Out of Memory errors - the perl seems to wants to read the
>whole file into memory before looking at it at all.
>
>At the moment is opens the file as such:
>	open( IN, "chunk.txt" ) or die "Hrm. Couldn't open the file./n";
>
>And then just runs through line by line:
>	foreach my $line ( <IN> )

try
while (my $line = <IN>)
or
my $line;
while ($line = <IN>)

>	{
>(insert a few possible regexp matches in `if` statements here. simple stuff)
>	}
>
>So, how do you get perl to not load the whole file into memory?
>
>.../Nemo


-- 
--
Kim Holburn  Network Consultant  Ph: +61 2 61258620 M: +61 0417820641
Email: kim.holburn at anu.edu.au - PGP Public Key on request

Life is complex - It has real and imaginary parts.
     Andrea Leistra (rec.arts.sf.written.Robert-jordan)




More information about the linux mailing list