Re: huge file : parsing problem



Hi

thanks for the help!! After it worked i can't say how happy i was :).

pardon me for my negligence in calling it the traditional method ;).
I just meant traditional in my history :p.

once again,
thanks a lot
Saurabh

On 3/29/06, Jay Savage <daggerquill@xxxxxxxxx> wrote:

On 3/29/06, Saurabh Singhvi <saurabhsinghvi@xxxxxxxxx> wrote:
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>) {

I don't think most people would call that the the "traditional"
approach. The standard idiom is:

while (<FILE>) {
chomp;
if ($min > $_ ) {
$min = $_ ;
}
elsif ($max < $_) {
$max = $_ ;
}
}

Unlike 'foreach', 'while'only reads a line (in this case) at a time,
which is why people use it for file operations and iterating over
arbitrarily-sized lists.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [ ] blogable; [ x ] ask first; [ ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com http://www.dpguru.com http://www.engatiki.org

values of β will give rise to dom!