in reply to Returning _which_ pattern matched...?
bikeNomad already answered your question, just let me elaborate a little bit on some of your statements
(Honestly, I don't know why; this was a suggestion from a more experienced engineer, ...)you should always try to see the logic behind such statements. In your case of matching different pattern against a string, this solution might be more effective (to shorten my code, consider $string to be in $_): if (/($m1)/ || /($m2)/ || /($m3)/) This is quicker then your big regex if you know that $m1 will be more frequent than $m2 (which in turn is more frequent than $m3).
The FAQs/resources don't offer any aid, and other Perl wizards say it can't be done.Just to show you TMTOWTDI - not that I recommend this if (/($m1(?{$match=1})|$m2(?{$match=2})|$m3(?{$match=3}))/) { ... you can execute code from within the regex ... and this is a really bad example of this powerful feature - but a way to do it :)
-- Hofmator
|
|---|