in reply to Most recent pattern match

Why not just:

my $regexp = Regexp::List ->new(modifiers => 'i',quotemeta => 0) ->lis +t2re(@patterns); if ($string =~ /$regexp/) { if (string =~ /insert|delete|update/i) { do something with $string }

DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Most recent pattern match
by Anonymous Monk on Jan 27, 2006 at 11:07 UTC
    ok thanks,a simple answer but I'd like to understand the implications of using or not using the $&. From my untrained eye it seems that answer you kindly posted will be scanning the string twice. Once for the general pattern search and then again for the specific pattern, whereas using $& would not involve the second string scan ?

      I thought, without trying it, that the hit from the second match would be compensated for by not using $&, but benchmark tests I tried indicate that that is not the case. I didn't see any additional hit as a result of using $& at all!

      I guess the moral is: try the simple stuff, but validate assumptions.


      DWIM is Perl's answer to Gödel