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.