Perl Monk, Perl Meditation | |
PerlMonks |
Re: regex in list contextby jakobi (Pilgrim) |
on Oct 28, 2009 at 13:22 UTC ( [id://803672]=note: print w/replies, xml ) | Need Help?? |
-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). ( 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.
cu & HTH, Peter -- hints may be untested unless stated otherwise; use with caution & understanding.
In Section
Seekers of Perl Wisdom
|
|