PERL. size of Multi-dimensional array

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

PERL. size of Multi-dimensional array

Post 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?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

print scalar @{ $arrї0] };
User avatar
daven
Forum Contributor
Posts: 332
Joined: Tue Dec 17, 2002 1:29 pm
Location: Gaithersburg, MD
Contact:

Post 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.
Post Reply