in reply to Re: perl performance vs egrep
in thread perl performance vs egrep
Would it give a speed improvement to prepare the regex in advance with qr//?No, it wouldn´t. At least not as long the regex is, like here, the only one within the loop. The qr//-operator is useful when you have the need of matching the same string to multiple regexes/patterns, like in
Using qr// doesn´t even help in code like@p = ( qr/^abc/, qr/abc$/, ); for $f ( @foo ) { for $p ( @p ) { do_stuff() if $f =~ $p; } }
because in such a case internal perl optimizations come into play.while ( $foo =~ /^abc/ && $foo =~ /abc$/ ) { do_stuff(); }
|
|---|