in reply to not able to get last index of array

I'm not quite sure what you want here. The numeric sort and your question implies that you want the max value? If that is what you want:
#!/usr/bin/perl use strict; use warnings; use List::Util qw(max); #CORE nothing to install # changed the order to make max value # in the middle of @numbers my @numbers = (15,5,7,3,90,9,1,20,13,9,8, 15,16,2,6,12); print "max is =", max(@numbers), "\n"; __END__ max is =90
Update: I thought that I should point out that you can re-assign the sorted array back to the same variable....
#!/usr/bin/perl use strict; use warnings; # changed the order to make max value # in the middle of @numbers my @numbers = (15,5,7,3,90,9,1,20,13,9,8, 15,16,2,6,12); @numbers = sort {$a <=> $b} @numbers; print "max = $numbers[-1]\n"; print "next to max = $numbers[-2]\n"; __END__ max = 90 next to max = 20
And yes, if 90 appeared twice, this changes things as both of these would be the same.