Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Script far too slow with large files - wisdom needed!

by RichardK (Parson)
on Jan 21, 2016 at 17:53 UTC ( [id://1153308]=note: print w/replies, xml ) Need Help??


in reply to Script far too slow with large files - wisdom needed!

It might improve things a bit if you rearrange your if statements, you don't need to check ($A + $B == 2...) for each line of the input file, as you know that $B can only change when you've matched RTINSECONDS so you could do this instead :-

if ($line =~ /TITLE=(.*)/) { $title=$1; } elsif ($line =~ /RTINSECONDS=(.*)/) { $RT=$1; if ($title && grep {$_ eq $TI} @IDS) { $IDrtPairs{$TI}=$RT; $title = undef; } }

As already mentioned it will be better to use a hash, so you should do that too :)

The example input data looks like TITLE & RTINSECONDS are always at the beginning of the line so you could anchor your regexs too, so it can reject non matching lines quicker. i.e. /^TITLE=(.*)/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2024-04-18 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found