Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by RichardK (Parson)
on Jan 21, 2016 at 17:53 UTC ( #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
Node Status?
node history
Node Type: note [id://1153308]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-11-17 09:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My code is most likely broken because:
















    Results (202 votes). Check out past polls.

    Notices?