I am in search of the index of the last nonzero element in the array. So, considering:
my @array = (0,0,5,9,0,0,0,7,0,3,0,0);
my $indexLastNonZero = insertElegantMethodHere(@array);
I have done this:
for my $i (0 .. $#array) {
$indexLastNonZero = $i if $array[$i] != 0;
};
I work, but for some reason I can't help but feel that there should be a super elegant (smarter? Good? More efficient?) Way to do this in perl. I looked at List :: Utils, but did not find a nice way there and would like to use a module independent of it.
Any thoughts?
Greetings
source
share