in reply to Looking for ways to speed up the parsing of a file...

If you want to speed up your code you have to know where you're spending your time. The best tool for this job is a profiler. Usually I would suggest Devel::DProf but you don't have any subroutines. Something line-oriented like Devel::SmallProf might be better. Once you know where your program is spending most of its time you can focus on improving that part.

One thing that jumps out at me skimming your code is this pattern:

if ($_ =~ /^\s+total wire length\:\s+\d.*\d\s*/) { ($NetLength) = $_ =~ /^\s+total wire length\:\s+(\ +d.*\d)\s*/;

There's no need to use two regexes here, and also no need to be explicit about $_ (it's the default match target). You can just do:

if (/^\s+total wire length\:\s+(\d.*\d)\s*/) { $NetLength = $1;

That should shave off a bit of time.

Another possibility to consider that profiling won't immediately suggest is parallellization. Do you have multiple CPUs or multiple machines at your disposal? If so, divide the file into pieces and hand them off to multiple processes to work on simulataneously.

-sam

Replies are listed 'Best First'.
Re^2: Looking for ways to speed up the parsing of a file...
by pc88mxer (Vicar) on May 17, 2008 at 19:26 UTC
    The OP also wants to test if the text following the colon is a numeric value or something else. It still can be done with one regex, though:
    if (/^\s+total wire length\:\s+(\d.*\d)?/) { if (defined($1)) { $NetLength = $1; $c++; } else { $NetLength = "NaN"; } }