huge file : parsing problem



HI there,

I have a huge file (~7GB) of text data. I need to parse it to extract
something : basically minima and maxima, and then i need to quantify
the data into an output file based on ranges.

Now the problem is that the traditional method of opening and foreach
which is as follows:

open(FILE,"data.txt");
$min = 100;
$max = 0;

foreach $data (<FILE>) {
if ($min > $data ) {
$min = $data ;
}
elsif ($max < $data) {
$max = $data ;
}
}
print $max, $min;
close FILE;

fails to work, as perl is trying to load the complete file into memory!

Now i also tried changing it to STDIN instead, by catting the data from
the text file.

../script.pl < data.txt

but this too gave the same error

Out of memory!

So kindly help me on how to do this thing.

thanks
Saurabh


Relevant Pages

  • Re: huge file : parsing problem
    ... basically minima and maxima, and then i need to quantify ... Now the problem is that the traditional method of opening and foreach ... as perl is trying to load the complete file into memory! ... Perl tutorials at http://perlmonks.org/?node=Tutorials ...
    (perl.beginners)
  • Re: [PATCH] Added CONFIG_VFAT_FS_DUALNAMES option
    ... so what is your estimate of XP crash probability? ... memory sticks, there will eventually be a WinXP bluescreen. ... has a highly optimized maxima implementation. ...
    (Linux-Kernel)
  • Re: "Out of memory!" ???
    ... if there is enough memory to ... process the array in a loop by using "foreach". ... You make heavy use symbolic references. ... each iteration of the outer most foreach loop, ...
    (comp.lang.perl.misc)
  • Re: Frequency in large datasets
    ... runs out of memory. ... than using foreach. ... down into smaller chunks of about 5 gigs each. ...
    (comp.lang.perl.misc)
  • Re: Review of my performance analysis
    ... >no difference what the actual maxima are. ... RAID-1 with faster disks ... external RAID-1 enclosure with battery-backed memory. ... would reduce my SCO I/O buffers back down to minimal levels to ensure ...
    (comp.unix.sco.misc)