But in the second line, we’re assigning to the scalar variable $bar, which now contains the number of items in the list.
This isn't correct in this example; in scalar context, the comma evaluates the expression to the left and to the right of it and returns the expression to the right. So it happens to return 3 in this case because that's the last expression. Returning the size in scalar context is behavior specific to array variables and functions like grep (but many functions do something different, as you note).
This isn't correct in this example; in scalar context, the comma evaluates the expression to the left and to the right of it and returns the expression to the right. So it happens to return 3 in this case because that's the last expression. Returning the size in scalar context is behavior specific to array variables and functions like grep (but many functions do something different, as you note).
Thanks! I’ve made the correction.
True. I usually use strings or numbers like 101, 102 in examples and tests to not fall into this trap.