S
sydches
Hi,
I am a beginner (or worse) at Perl.
I have a need to find the longest line (record) in a file. The below
code works neatly for small files.
But when I need to read huge files (in the order of Gb), it is very
slow.
I need to write an output file with stuff like:
Longest line is... occurring on line number...
There are ... lines in the file
The same file is crunched using C in about 30 milliseconds!
The difference in run times of Perl/VbScript and C is a significant
one.
Could someone help me in finding what way I could make Perl work the
best way for processing huge files such as these?
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
my $prev=-1;
my $curr=0;
my ($sec,$min,$hour,$com) = localtime(time);
print "Start time - $hour:$min:$sec \n";
open(F1, "c:\\perl\\syd\\del.txt");
while (<F1>)
{
$curr = index($_, "\x0A");
if($curr > $prev)
{
$prev = $curr;
}
}
close(F1);
my ($sec,$min,$hour,$com) = localtime(time);
print "End time - $hour:$min:$sec \n";
print "Lengthiest record length: $prev \n";
The output times for a 1 Gb is
Start time - 20:32:31
End time - 20:34:28
Lengthiest record length: 460
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I am running this on a laptop with Windows XP, 1.7 GHz processor with
1 Gb of RAM
I am using ActivePerl
Thanks in advance!
Syd
I am a beginner (or worse) at Perl.
I have a need to find the longest line (record) in a file. The below
code works neatly for small files.
But when I need to read huge files (in the order of Gb), it is very
slow.
I need to write an output file with stuff like:
Longest line is... occurring on line number...
There are ... lines in the file
The same file is crunched using C in about 30 milliseconds!
The difference in run times of Perl/VbScript and C is a significant
one.
Could someone help me in finding what way I could make Perl work the
best way for processing huge files such as these?
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
my $prev=-1;
my $curr=0;
my ($sec,$min,$hour,$com) = localtime(time);
print "Start time - $hour:$min:$sec \n";
open(F1, "c:\\perl\\syd\\del.txt");
while (<F1>)
{
$curr = index($_, "\x0A");
if($curr > $prev)
{
$prev = $curr;
}
}
close(F1);
my ($sec,$min,$hour,$com) = localtime(time);
print "End time - $hour:$min:$sec \n";
print "Lengthiest record length: $prev \n";
The output times for a 1 Gb is
Start time - 20:32:31
End time - 20:34:28
Lengthiest record length: 460
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
I am running this on a laptop with Windows XP, 1.7 GHz processor with
1 Gb of RAM
I am using ActivePerl
Thanks in advance!
Syd