Question : How to count number of elements in an array of arrays?

Hello coders,

I have an array of arrays called $list_of_templates.  I can get the count of this array by doing @list_of_templates.  Currently this array has two elements in it (both of which are arrays).  

What I can't seem to figure out is how to get a count of the # of elements stored in each of the arrays in the list_of_templates array.

I tried @list_of_templates[$j] but this doesn't work.  It prints out ARRAY(0xd2a400) twice times with the code below.  

What am I doing wrong?

Code Snippet:
1:
2:
3:
4:
for ($j = 0; $j < @list_of_templates; $j++) {
  $m_size = @list_of_templates[$j];
  print $m_size;
}
Open in New Window Select All

Answer : How to count number of elements in an array of arrays?

1:
2:
3:
4:
for ($j = 0; $j < @list_of_templates; $j++) {
  my $m_size = @{$list_of_templates[$j]};
  print "$m_size\n";
}
Open in New Window Select All
Random Solutions  
 
programming4us programming4us