Skip navigation.
Your source for Perl tips, howto's, faq and tutorials
( categories: )

Array index values start from zero.To obtain the last index value of an array ('n-1' if the array has 'n' elements), use the following syntax:


To get the value of the last element of the array, you can either do:





@array = qw(rock paper scissors);
print "Last index value of array: " . $#array . "\n";
print "Value of last element of array: " . $array[-1] . "\n";