in reply to
How can one call the lowest value of an array by reference?
This could probably be refactored more elegantly, but it seems to do the job in a single pass without undue complexity.
use strict;
use warnings;
my @values = qw( 5 3 2 12 2 );
my @names = qw( Cat Bat Cow Dog Rat );
my $min;
my @indices;
foreach my $ix ( 0 .. $#values ) {
if( ! defined $min or $values[$ix] < $min ) {
@indices = ($ix);
$min = $values[$ix];
}
elsif( $min == $values[$ix] ) {
push @indices, $ix;
}
}
print "Lowest value: $min\n";
print "$_ => $names[$_]\n" for @indices;