in reply to regex in list context
-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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex in list context
by kyle (Abbot) on Oct 28, 2009 at 14:55 UTC | |
by LanX (Saint) on Oct 29, 2009 at 00:17 UTC |