In places where you want the index of the last element (e.g. in foreach loops), you'd use the syntax
$#{ $arrayref }
It's just like the usual
$#array, but with an
array reference value in place of the
array variable name. And you need the curly braces.
So, to iterate over the elements of an array to which you have a reference, using an index counter:
for ( my $i = 0; $i <= $#{ $arrayref }; $i++ )
{
print "$arrayref->[$i] \n";
}
I think this is useful when you have arrays of arrays, or even more complex data structures.