Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Parsing Large Text Files For Performance

by bigbot (Beadle)
on Jan 31, 2011 at 06:41 UTC ( [id://885203]=note: print w/replies, xml ) Need Help??


in reply to Parsing Large Text Files For Performance

Here's what I've come up with so far (using some of the improvements suggested and benchmarking using GrandFather's example):
my $hdr_search = qr{^\-{4}\s\d}; sub useIndex { my ($ip1, $ip2, $lines) = @_; for my $line (@$lines) { unless (($line =~ $hdr_search) || ($header)) { next; } unless ($line =~ $hdr_search) { print $line; ## Print matching packet body next; } if (0 > index ($line, $ip1) || (0 > index ($line, $ip2))) { $header = 0; next; } else { print "\n$line"; ## Print matching packet header $header = 1; } } }
Using the index function along with getting rid of IF cases early has definitely sped things up considerably. Thoughts?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://885203]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-24 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found