in reply to How do I find the size of an array?
$size = @array;
Remember that the size of an array is not the same as the last element of an array. Since indexing of elements starts at zero, the last element of a ten-element array is 9. See the following code:
my @array = qw/1 2 3 4 5/; print scalar @array, "\n"; # Size of array print $#array, "\n"; # Last element of array
And the output:
5
4
Originally posted as a Categorized Answer.
|
|---|