Perl-Sensitive Sunglasses | |
PerlMonks |
Re: Did I match or didn't I?by gbarr (Monk) |
on Oct 18, 2001 at 00:23 UTC ( [id://119552]=note: print w/replies, xml ) | Need Help?? |
I am assuming that you want $result to contain the contents of the ()'s if the pattern matches, but "default" otherwise. Providing the ()'s cannot return "0" or "" then you could use my ($result)= (m[pattern(group)])[0] || "default"; The outer ()'s put the RE into a list context, then we pick off the first element, which will be the contents of the matching parens
In Section
Seekers of Perl Wisdom
|
|