http://www.perlmonks.org?node_id=617776


in reply to How can I find the index of the biggest element in an array?

Given an array @data containing numeric data:

my $idxMax = 0; $data[$idxMax] > $data[$_] or $idxMax = $_ for 1 .. $#data;

is not only compact but, somewhat surprisingly perhaps, comparable in speed to caching $data[$idxMax] as shown in most of the other variants. A cache variant is worth using if an expensive calculation is required in the comparison or a very large array is being processed.