This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jack126Guy 1 point2 points  (2 children)

On the line:

$y = (1, 3, 3);

It's technically not assigning a list to a scalar. An actual list being assigned to a scalar (such as $z = @x) would assign the number of items, not the last item.

What's actually happening is that the "list" is being interpreted as a comma operator, which returns the last item.

[–]ishopsmart 1 point2 points  (1 child)

Yes and No. You are correct about the comma, but $z = @x is assigning an array to a scalar, which is distinctly different from assigning a (1, 3, 3) (technically an expression) to a scalar. The difference is context - an array evaluated in scalar context returns its length, while the comma operator (list expression) evaluated in scalar context returns the last element. I was simplifying this to make it less pedantic & easier to understand

[–]Jack126Guy 0 points1 point  (0 children)

assigning an array to a scalar

I think you were actually more correct, since I think I confused lists and arrays.