-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.

cu & HTH, Peter -- hints may be untested unless stated otherwise; use with caution & understanding.

In reply to Re: regex in list context by jakobi
in thread regex in list context by azadian

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.