Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Speed of Perl Regex Engine

by runrig (Abbot)
on Nov 28, 2012 at 16:17 UTC ( #1006065=note: print w/ replies, xml ) Need Help??


in reply to Speed of Perl Regex Engine

Does it need to be a regex? If you can live with an exact match, then I'd use a hash:

my %want_global = map { ($_ => 1) } qw( THIS THAT ANOTHER ); ... if ( $want_global{$global} ) { ... }
If you really need to have regexes, then put them in an array instead of a single regex, it will generally perform better than a joined single regex (and put the most likely things to match first, if possible):
my @wanted_re = ( qr/^AB/, qr/^CD/, ); sub want_global { my $g = shift; for my $re (@wanted_re) { return 1 if $g =~ /$re/; } return; }
Update: I see that maybe you want 'unwanted global' logic...whatever...the above still applies...adjust to suit needs.


Comment on Re: Speed of Perl Regex Engine
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2014-04-18 06:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (462 votes), past polls