To explain the "Do what I mean" behavior you show in your example......
It makes no sense for a list to be operated on by the concatenation operator. The concatenation operator takes a scalar on both sides. Thus, if you were able to call "wantarray" on the concatenation operator you would find that it doesn't "want a list." That fact forces the @foo array to be evaluated in scalar context, and the results of that evaluation to be concatenated with whatever is on the other side of the "." operator. As we all know, the good book says, "There is no such thing as a list in scalar context." When you put an @array somewhere that a scalar is expected, you get the behavior documented for @array in scalar context; you see how many elements it contains.
If, on the other hand, you say, print @foo you will see that print accepts a list (and prints a list). If you could call wantarray (an apparent misnomer with origins in the dark ages when lists were called arrays too) on "print" it would return true. And so, @foo is evaluated in list context when evaluated as an arguement of 'print'.
The most peculiar thing I can think of in all this is the fact that concatenation operator doesn't accept a list while variable interpolation into a string does. I know that "concatenating" lists is what join is for. But to a relative greenie like me, it seems inconsistant. (For example, "This @array interpolates as a list.")
Perhaps our lives are simpler and better because arrays inside of literal strings are seen as arrays in list context, but nevertheless, why that "works" when concatenation doesn't is something that the real experts will have to reveal.
Dave
In reply to Re: Array in scalar context.
by davido
in thread Array in scalar context.
by the_0ne
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |