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

You've already gotten the best suggestions, so here's some minor ones: Replace
if (($TotalNets == 50000) || ($TotalNets == 100000) || ($Total +Nets == 250000) || ($TotalNets == 500000) || ($TotalNets == 1000000) +|| ($TotalNets == 1500000) || ($TotalNets == 2000000) || ($TotalNets +== 3000000)) {
with a hash (e.g. %Nets) containing the above values and
if ( $Nets{$TotalNets) ) {
I like pc88mxer suggestion, but I notice that (for example) 150,000 is not in your test, so modulo 50,000 would give you a false positive.

Another suggestion would be to replace

$_ =~ s/^ *//; $_ =~ s/ *$//; @DriverLine = split (/\s+/,$_);
with
@DriverLine = split( /\s+/, (( /^\s*(\S.*)\s*$/ ) ? $1 : $_ ) );

The code hasn't been tested, and I can't swear to the efficiencies.

Replies are listed 'Best First'.
Re^2: Looking for ways to speed up the parsing of a file...
by Anonymous Monk on May 17, 2008 at 23:41 UTC

    Split has a magical whitespace incantation:

    $_ = ' foo bar baz '; print "'$_'\n" for split ' ';

    So you don't need to trim leading or trailing whitespace to get the desired result.

Re^2: Looking for ways to speed up the parsing of a file...
by Anonymous Monk on May 17, 2008 at 22:01 UTC
    As to the final suggestion, it might be more efficient to replace what is in effect two regexes (plus some logic) with just one:

    >perl -wMstrict -e "for (@ARGV) { my @s = m{ \S+ }xmsg; local $\" = ':'; print qq('$_' :@s: \n); } " "" " " " " " " " " "foo" " foo" "foo " " foo " "foo bar" " foo bar" "foo bar " " foo bar " "foo bar baz" " foo bar baz" "foo bar baz " " foo bar baz " '' :: ' ' :: ' ' :: ' ' :: ' ' :: 'foo' :foo: ' foo' :foo: 'foo ' :foo: ' foo ' :foo: 'foo bar' :foo:bar: ' foo bar' :foo:bar: 'foo bar ' :foo:bar: ' foo bar ' :foo:bar: 'foo bar baz' :foo:bar:baz: ' foo bar baz' :foo:bar:baz: 'foo bar baz ' :foo:bar:baz: ' foo bar baz ' :foo:bar:baz:
      Or probably even more efficient, come to think of it, just to use the default  split parameters:

      >perl -wMstrict -e "for (@ARGV) { my @s = split; local $\" = ':'; print qq('$_' :@s: \n); } " "" " " " " " " " " "foo" " foo" "foo " " foo " "foo bar" " foo bar" "foo bar " " foo bar " "foo bar baz" " foo bar baz" "foo bar baz " " foo bar baz " '' :: ' ' :: ' ' :: ' ' :: ' ' :: 'foo' :foo: ' foo' :foo: 'foo ' :foo: ' foo ' :foo: 'foo bar' :foo:bar: ' foo bar' :foo:bar: 'foo bar ' :foo:bar: ' foo bar ' :foo:bar: 'foo bar baz' :foo:bar:baz: ' foo bar baz' :foo:bar:baz: 'foo bar baz ' :foo:bar:baz: ' foo bar baz ' :foo:bar:baz: