Consider this Perl code
my @a=[[1]];
print $a[0][0];
**output**
ARRAY(0x229e8)
Why does it print an ARRAY
instead of 1
? I would have expected @a
to create an array of size 1 with a reference to a second array containing only one element, 1
.
This stuff is tricky. You have assigned @a
as a list containing a reference to an array that contains a reference to an array, which is one more extra level of indirection than you were expecting.
To get the results you expect, you should have said
@a = ( [ 1 ] );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With