my @c = combine(5,@n); # get array of arrays my @A = @$c[0]; # get first sub-array
Because the 'precedence' (if that's the proper term here) of the @ array dereference sigil is so high, the expression @$c[0] attempts to dereference an array reference held in the $c scalar (not in the @c array) and then access the element at index 0 in the referenced array. (Update: Actually, my first thought was that @$c[0] would look like a 'degenerate' array slice, like @x[0]; not sure why the appropriate warning was not generated.) The expression @{ $c[0] } is what is needed in the given example.
>perl -wMstrict -MData::Dump -le "my @c = (['x', 'y'], ['a', 'b'], ['c', 'd']); my $c = ['foo', 'bar']; ;; my @A1 = @ $c[0] ; my @A2 = @{ $c[0] }; dd \@A1; dd \@A2; " ["foo"] ["x", "y"]
In reply to Re^7: Perl list items
by AnomalousMonk
in thread Perl list items
by robertw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |