use List::Util qw(min max sum);
my $min = min keys %hash;
my $max = max keys %hash;
my $avg = sum(keys %hash) / keys %hash;
# Won't work: avg keys %hash;
Untested, btw. I'm not sure what you mean with shortest and longest numerical key. I'll assume here you mean minimum and maximum. If you mean shortest string-wise, use minstr and maxstr instead.
Update: Doh! There is no avg function. Code is updated to reflect that.
[ ar0n ]
| [reply] [d/l] [select] |
use Math::VecStat qw(average);
my $avg = average( keys %hash );
For more stats, take PDLJeroen
"We are not alone"(FZ) | [reply] [d/l] |
I'm surprised nobody else's HOMEWORK-dar has gone off.
Is this your first Perl class or what?
-- Dave | [reply] |
Anonymous Monk:
Use the keys keyword and you now have a list of the keys in the hash. This list will be in no particular order. (values will give you the values.) Now, just use whatever favorite method you have to find the min, max, and avg from an list. (You do know how to find the min, max, and avg from a list, right?) | [reply] |