I think you're missing my point. It does seem to consistently evaluate the arguments on both sides in a SCALAR context if it's an EXPR and not an actual variable name (similar to how (say) keys requires something literally begining with a % to work upon). That means that your constant sub is being evaluated in scalar context returning the final element of the LIST, just as everywhere else you have a true LIST in scalar context.

1 #!/usr/local/bin/perl5.10.0 2 use feature ":5.10"; 3 4 BEGIN { 5 sub ctx () { 6 my @caller = caller(1); 7 say "$caller[3]:$caller[2] wantarray: ", 8 defined $caller[5] 9 ? ( $caller[5] ? "yes" : "no" ) 10 : "undef"; 11 } 12 13 sub ret_scalar () { ctx; "a" } 14 sub ret_list () { ctx; @{[ qw/a b c/ ]} } 15 } 16 17 ret_scalar; 18 my $a = ret_scalar; 19 my @a = ret_list; 20 21 my $list_in_scalar = ret_list; 22 say "list in scalar: ", $list_in_scalar; 23 24 my @scalar_in_list = ret_scalar; 25 say "scalar in list: ", join( ", ", @scalar_in_list ); 26 27 say "match" if ret_scalar ~~ ret_list; 28 say "match" if ret_list ~~ ret_scalar; 29 say "match" if ret_scalar ~~ [ ret_list ]; 30 31 __END__ main::ret_scalar:17 wantarray: undef main::ret_scalar:18 wantarray: no main::ret_list:19 wantarray: yes main::ret_list:21 wantarray: no list in scalar: 3 main::ret_scalar:24 wantarray: yes scalar in list: a main::ret_scalar:27 wantarray: no main::ret_list:27 wantarray: no main::ret_list:28 wantarray: no main::ret_scalar:28 wantarray: no main::ret_scalar:29 wantarray: no main::ret_list:29 wantarray: yes match

I will grant you that I couldn't find documentation in my quick once over explicitly documenting that EXPRs would be evaluated in scalar context. In any case the quick fix is to either change your constant sub to return an arrayref or wrap the call to the constant sub in an anonymous arrayref constructor.

Update: Duur, as is pointed out below it's a binary operator so that's probably why it's not explicitly spelled out.

Update the second: Tweaked ret_list to behave more like the sub generated by the OP's constant call than my initial version's sub ret_list () { ctx; qw/a b c/ } did; still doesn't match because of the scalar context imposed but the exact value that doesn't match is 3 rather than 'c'.

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re^3: 5.10 smart match behaviour by Fletch
in thread 5.10 smart match behaviour by zgrim

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.