Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I deference this Perl array of arrays?

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.

like image 968
Mike Avatar asked Nov 28 '22 06:11

Mike


1 Answers

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 ] );
like image 194
mob Avatar answered Dec 21 '22 11:12

mob