We start with the following two statements:
@a starts as an empty array with no elements.$b to 10.
Now look at this construction:
@{$a[$b]}
To understand what we can start in the middle: $a[$b] index element 10 of @a array.
Now we can work from there: @{...} considers its contents as a reference to an array. Therefore, @{$a[$b]} treats the contents of element 10 of @a as a reference to an anonymous array. That is, the scalar value contained in $a[10] is a reference to an array.
Now the layer in push:
push @{$a[$b]}, $c;
In the anonymous array specified in element 10 @a , you push the value of $c , which is the character "a". You can access this item as follows:
my $value = $a[10]->[0]; # character 'a'
Or contraction,
my $value = $a[10][0];
If you moved another value to @{$a[10]} , you will have access to it at:
my $other_value = $a[10][1];
But what about $a[0] through $a[9] ? You only press the value in $a[$b] , which is equal to $a[10] . Perl automatically expands the array to accommodate this 11th element ( $a[10] ), but leaves the value in $a[0] through $a[9] as undef . You mentioned that you tried this:
print "@a\n";
Interpolating an array into a string causes its elements to be printed with a space between them. So you have not seen this:
ARRAY(0xa6f328)
Did you see that:
ARRAY(0xa6f328)
... because there were ten spaces before the 11th element, containing an array reference.
If you used a script with use warnings at the top, you would see this instead:
Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. Use of uninitialized value in join or string at scripts/mytest.pl line 12. ARRAY(0xa6f328)
... or something very similar.
Your structure now looks like this:
@a = (undef,undef,undef,undef,undef,undef,undef,undef,undef,undef,['a'])
If you ever want to take a look at the data structure rather than using simple printing, follow these steps:
use Data::Dumper; print Dumper \@a;