Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: List context, expression precedence, and ()

by pmas (Hermit)
on Jul 21, 2001 at 22:54 UTC ( [id://98685]=note: print w/replies, xml ) Need Help??


in reply to Re: List context, expression precedence, and ()
in thread List context, expression precedence, and ()

I do like lists, it is so much more flexible for passing parameters, easy to build optional parameters, etc. I just need always be concerned about scalar/list context in expressions, that's all.

I found japhy's article about scalar/list context, and it was real eye-opener, when I learned that

sub A { return ('a', 'b', 'c'); } $a = A(); # $a gets value 'c' ($b) = A(); # $b gets value 'a'
As japhy explains:
The A() function, in scalar context, has the comma operator act on the comma separated series of values, and so $a is set to 'c' which makes sense. $b, however, gets the value 'a', because it invokes list context on the function, which returns a list.

japhy: ++ for you!

pmas
To make errors is human. But to make million errors per second, you need a computer.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-25 21:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found