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;

Dave

Replies are listed 'Best First'.
Re^2: How can one call the lowest value of an array by reference?
by supriyoch_2008 (Monk) on Dec 12, 2012 at 10:20 UTC

    Hi Dave,

    Thanks for your prompt reply. Your code is simple for me to understand. It has solved my problem.

    With regards,