in reply to Re^3: extract only smallest numbers
in thread extract only smallest numbers
With this single line instead:$hash{$name} = $code;
ie. You assign the latest value only if it's the first value for that key name, or if it's smaller than any previous value so far.$hash{$name} = $code if !defined $hash{$name} || $code < $hash{$name};
I'd recommend defined over exists in this case. If the hash key somehow did exist with an undefined value, the exists test would let it through, and then you'd then get a warning (under use warnings) when you got to the 'less than' comparison.
Using defined instead will avoid this potential banana skin, and give you the correct outcome.
|
|---|