sub min_idx { my ($ar) = @_; return undef if !@$ar; my $idx = 0; for (1..$#$ar) { $idx = $_ if $arr->[$_] > $arr->[$idx]; } return $idx; }