Page 1 of 1

PERL. size of Multi-dimensional array

Posted: Tue Mar 18, 2003 4:20 pm
by daven
In PERL: I am having difficulty finding the number of elements in the Nth dimension of an array. I can get the size of the base array, but anything deeper I am dying on.

Ex:
@arr;
$arr[0]="hello";
$arr[1]="goodbye";

$arr[0][0]="greetings";
$arr[0][1]="salutations";
$arr[0][2]="yo";
$arr[1][0]="see ya";
$arr[1][1]="adios";

$arr_len=scalar(@arr); # $arr_len = 2

What I am trying to do is find the number of elements in $arr[0] (should be 3), and $arr[j][k][etc.,].

I have read the Camel, and hunted on Google to no avail. Help?

Posted: Tue Mar 18, 2003 5:45 pm
by volka
try

Code: Select all

print scalar @{ $arrї0] };

Posted: Tue Mar 18, 2003 9:23 pm
by daven
*sighs* Thank you Volka. That works perfectly.

Yet again, I beat my head into a wall so continually that I forget to use the door.