On Tue, Jul 28, 2009 at 10:42:01PM +0200, Moritz Lenz wrote:
: I guess when I initialize @a[0] = [] it's the same, because then @a[0]
: is still a scalar, right?

No, as in Perl 5 [] still produces a scalar object that hides the arrayness
from list context, so it's like:

    $b = [];
    @a[0] = $b;

It doesn't unwrap the scalar object to see what's in it.

: Only when I wrote @a[0] := [] I'd get all items in @a[0].

That binds the Array in place of the current @a[0] container, just as

    $b = [];
    @a[0] := $b;

would.

Just as $obj and @$obj default differently in list context, so do
[] and ().  To put it another way, Array and Hash objects don't
naturally interpolate into list context without some help from @ or %
syntax (or equivalent method call).  If I say:

    @a = 42, [1,2,3], { foo => 1, bar => 2, baz => 3 };

then @a will always end up with exactly 3 elements, just as if I'd
said:


    $a = 42;
    $b = [1,2,3];
    $c = { foo => 1, bar => 2, baz => 3 };
    @a = $a, $b, $c;

Larry

Reply via email to