perlquestion
Boudicca
Greetings, noble monks -- I have a quandry:<p>
Say you have a string and a few patterns to try matching, something like this (it's dinky, please forgive):<p>
$string = "clintonesque";<br>
$m1 = "Clinton";<br>
$m2 = "Bush";<br>
$m3 = "Reagan";<br>
if ($string =~ m/($m1|$m2|$m3)/i) {<br>
print "Got a match.\n";<br>
} else {<br>
print "No match.\n";<br>
}<br>
<p>
What I want to know is _which_ of those three things ($m1, $m2, $m3) it matched first. Can it be done, or am I delusional?<p>
I should note that I'd like to put all of the match patterns into one monster regexp, instead of if/else-ing my way through a series of them. (Honestly, I don't know why; this was a suggestion from a more experienced engineer, in the interest of conserving computer juice with some pre-compiling.)
<p>
The FAQs/resources don't offer any aid, and other Perl wizards say it can't be done. I would be intensely grateful for any ideas...
<p>
Thanks!