Usually where Perl operators return false they do so by either returning an empty string or 0

Actually, they return both at the same time.

What is the actual value returned by a failed regular expression match?

Please see this table of regular expression return values. print Dumper( "a" =~ m/b/ ); is providing list context to its arguments, so it's the same as writing print Dumper( );

Why does ... !~ returns the more common empty string version?

Because "a" !~ m/a/ is the same as !('a' =~ /a/), and that returns Perl's special false value.

Update: Your initial issue can be solved by scalar or PerlX::Maybe:

warn Dumper( { a => scalar( "a" =~ m/b/ ), b => 'asdf' } ); use PerlX::Maybe; warn Dumper( { maybe a => "a" =~ m/b/, b => 'asdf' } );
Eventually I realised that the failed match for the regular expression was somehow tricking the first comma to be evaluated in a scalar context, rather than a list context (note that if the regular expression matches then it returns 1 and the comma is evaluated in a list context).

Sorry, no, your analysis is not correct - the hash assignment is entirely in list context, in the examples you showed there's no scalar context going on there at all; only in the my $a = ... assignments. Update 2: To nitpick myself a little, the arguments to the =~ operator are in scalar context.


In reply to Re: What does a failed regular expression match actually return? (updated) by haukex
in thread What does a failed regular expression match actually return? by Anonymous Monk

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.