-MO=Deparse shows print "MATCHED\n" if @list = !('foo bar baz' =~ /\bbar\b/);, which explains your observation. Which I read as an implicit "cast" from scalar not to list context for the assignment, similar to @list=5 implying @list=(5).
(initially I thought about about =~ possibly being used in list context as well, but that's nonsensical).
I've problems imagining sensible semantics for an alternate implementation of list context (matching substrings) on a non-match operator like !~, so the current solution above seems sanest to me.
However man perlop could be more explicit: Binary "!~" is just like "=~" except the return value is negated in the logical sense. Elsewhere, same document: When there are no parentheses in the pattern, the return value is the list "(1)" for success. With or without parentheses, an empty list is returned upon failure.
In reply to Re: regex in list context
by jakobi
in thread regex in list context
by azadian
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |