Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: ~~ and list literal

by ikegami (Pope)
on Oct 27, 2012 at 00:15 UTC ( #1001146=note: print w/ replies, xml ) Need Help??


in reply to Re^2: ~~ and list literal
in thread ~~ and list literal

Why does "x" ~~ "a", "b", "c" always give 1?

It doesn't; it evaluates to "c".

"," is a very low precedence operator. "x" ~~ "a", "b", "c" means ("x" ~~ "a"), "b", "c", which evaluates to "c" in scalar context.

And why does "x" ~~ sub { "a", "b", "c" } also give 1?

It doesn't; it evaluates to "c".

"x" ~~ sub { "a", "b", "c" } is the same as scalar( sub { "a", "b", "c" }->($x) ). Since  "a", "b", "c" evaluates to "c" in scalar context, that is what is returned.


Comment on Re^3: ~~ and list literal
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1001146]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2014-12-23 03:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (134 votes), past polls