Hi, I have a question regarding the use of $& . In my code I use the Regexp::List module like so
my $regexp = Regexp::List ->new(modifiers => 'i',quotemeta => 0) ->lis +t2re(@patterns);

The contents of $regexp look like this
(?-xism:(?i:(?=[acdilrsuw])(?:create (?:t(?:able|rigger)|function|defa +ult|pro[cedure]|rule|view)|d(?:rop (?:t(?:able|rigger)|default|functi +on|rule|view)|elete )|s(?:p_(?:bind(?:efault|msg|rule)|drop(?:(?:g|ro +w)lockpromote|key)|p(?:laceobject|rimarykey)|rename(?:_qpgroup)?|set( +?:pg|row)lockpromote|unbind(?:efault|msg|rule)|add_qpgroup|chgattribu +te|foreignkey|hidetext)|etuser)|(?:alter|lock) table|(?:insert|update +) |remove java|writetext)))
What I need to do is to find out which pattern matched and then do something based on the answer. If the pattern matched was "insert update or delete" I need to take further action. The question is what is the best way of handling this ?
I've read some comments about the use of $& being bad to use for performance reasons
e.g.
my $regexp = Regexp::List ->new(modifiers => 'i',quotemeta => 0) ->lis +t2re(@patterns); if ($string =~ /$regexp/) { if ($& eq "insert" or $& eq "delete" or $& eq "update") { do something with $string } call a subroutine here... }
This example code may be called a considerable number of times (i.e. millions). Since I'm starting out in Perl I'd like to make sure I am writing reasonable code. So how do I do this without using $& ? Any help appreciated.

In reply to Most recent pattern match by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.