Personally I prefer the (TEST)?TRUE:FALSE method (C many many years ago) but extending the idea of using a list (but not clarity):-
($a,$throw_away) = (("abc" =~ /a(b)c/) , 'd');
if the RegEx doesn't match then you have a single element list containing 'd', if it does then 1st element is still 'b' the $throw_away variable just captures any remaining elements.
or$a = ( ("abc" =~ /a(b)c/) , 'd' )[0];
Taking this idea to an extreme, what about pulling set of values from the regex or setting all the variables to a set value.
($a,$b,$throw_away) = (("abcde" =~ /a(b)c(d)/),('UNDEFINED') x 3); print $a , "::" , $b ; # prints b::d and ($a,$b,$throw_away) = (("abcde" =~ /a(x)c(x)/),('UNDEFINED') x 3); print $a , "::" , $b ; # prints UNDEFINED::UNDEFINED
In reply to Re: Re: Regexp context with ||
by JamesNewman
in thread Regexp context with ||
by bsb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |