In Perl regex, the documentation says
... in scalar context,
$time =~ /(\d\d):(\d\d):(\d\d)/
returns a true or false value. In list context, however, it returns the list of matched values($1,$2,$3)
But how is it that when you provide an alternative option - when no match is found - TRUE or FALSE will be assigned even when in list context?
As an example, I want to assign the matched group to a variable and if not found, use the string value ALL.
my ($var) = $string =~ /myregex/ || 'ALL';
Is this possible? And what about multiple captured groups? E.g.
my ($var1, $var2) = $string =~ /(d.t)[^d]+(d.t)/ || 'dit', 'dat';
Where if the first group isn't matched, 'dit'
is used, and if no match for the second is found 'dat'
.