Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^4: List assignment in scalar context

by dragonchild (Archbishop)
on Jan 10, 2005 at 19:25 UTC ( #421053=note: print w/replies, xml ) Need Help??


in reply to Re^3: List assignment in scalar context
in thread List assignment in scalar context

So, based on what you're saying, $n2 should equal 5. Since @x isn't a scalar, it shouldn't affect the count of $n2 because I have scalar = list = list = list ... so, why doesn't that work?

Not to mention, where is it documented that When you have scalar = list = list, you will always get the count of items in the rightmost list in scalar. ?? I don't remember ever reading that ...

Being right, does not endow the right to be rude; politeness costs nothing.
Being unknowing, is not the same as being stupid.
Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Replies are listed 'Best First'.
Re^5: List assignment in scalar context
by !1 (Hermit) on Jan 10, 2005 at 19:32 UTC

    = is right associative. Thus you have list = list (rightmost) before you get scalar = list = list. The list in question has 3 elements. Of course in this case, I think the behavior of an array in scalar context has more to do with the overall result than anything else. Note that if you replace the array declaration with any list of the form ($a,$b,...), you still get the count in $n2.

    perldoc perldata, look for "List assignment in scalar context". Note that the extra parentheses around the rightmost assignment in the example are superfluous since they don't affect the order of operations.

    Also, to those downvoting my nodes in this thread: if the reason that you're downvoting my nodes is due to the lack of technical merit of my posts, feel free to /msg me or reply.

Re^5: List assignment in scalar context
by jonadab (Parson) on Jan 11, 2005 at 00:15 UTC
    Since @x isn't a scalar, it shouldn't affect the count of $n2 because I have scalar = list = list = list

    No, you don't. You have scalar = array = list = list, which, as far as the scalar is concerned, reduces to scalar = array, after the array is assigned its value. An array is not a list. The Camel is quite clear on that point. It's also clear on what an array returns in scalar context. No surprises there.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2021-09-26 07:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?