Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
my $regexp = Regexp::List ->new(modifiers => 'i',quotemeta => 0) ->lis +t2re(@patterns);
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 ?(?-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)))
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.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... }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Most recent pattern match
by GrandFather (Saint) on Jan 27, 2006 at 10:57 UTC | |
by Anonymous Monk on Jan 27, 2006 at 11:07 UTC | |
by GrandFather (Saint) on Jan 27, 2006 at 19:15 UTC | |
|
Re: Most recent pattern match
by BrowserUk (Patriarch) on Jan 27, 2006 at 12:55 UTC | |
by Anonymous Monk on Jan 27, 2006 at 13:56 UTC | |
by BrowserUk (Patriarch) on Jan 27, 2006 at 14:40 UTC | |
|
Re: Most recent pattern match
by grinder (Bishop) on Jan 27, 2006 at 11:43 UTC | |
|
Re: Most recent pattern match
by ikegami (Patriarch) on Jan 27, 2006 at 18:57 UTC |