smart matching question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Here showed is a piece from debugger
there are three parts

DB<10> x 'a' ~~('a','b')
0  ''

   DB<11> x 'a' ~~['a','b']
0  1

   DB<12> @a = ('a','b')

   DB<13> x 'a' ~~ @a
0  1

My question is: what is the difference between the first and the third
I think i miss a bit the point what is the difference betwwen @a and

Can someone help me to understand ?


Re: smart matching question

Quoted text here. Click to load it

Note that you should get a warning for useless use of constant in void
context here.

What is happening is simple. ('a', 'b') on the RHS is not a list. It is
'a' *comma* 'b'. Therefore, the value of ('a', 'b') is 'b'. 'b' does not
match 'a'. The result is false.



C:\DOCUME~1\asu1\LOCALS~1\Temp> perl -MO=Deparse
Useless use of a constant in void context at line 8.
use warnings;
use strict 'refs';
    $^H = q(1);
    $^H = q(1);
    $^H = q(1);
say 'yes' if ('???', 'b') ~~ 'a'; syntax OK

Note the '???' where 'a' used to be. That indicates that the constant
'a' has been optimized away.

Quoted text here. Click to load it

If you look at perldoc perlsyn ('Smart matching in detail'):

    Array   Any       array contains string    grep $_ eq $b, @$a

I don't know where this is explicitly stated, but the arguments to ~~
are evaluated in scalar context. Arrays, hashes, code blocks etc are
converted to references.


(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW: /

Site Timeline