in reply to How to get 2nd highest value from an array?
Update: Oops, i actually meant to say: Is there anyway to do this same thing on the values of a hash?
Do you mean just the values themselves or the keys based on the values? Here is some code for both cases:
For the second example, since we already have to specify a sort block, i choose to sort descending and use the subscript 1 and not -2. TIMTOWTDI. :)my %hash = ( 4 => 20, # second highest key 2 => 40, # second highest value 3 => 30, 1 => 50, 5 => 10, ); # second highest value print ((sort values %hash)[-2]); # key based on the second highest value print ((sort { $hash{$b} <=> $hash{$a} } keys %hash)[1]);
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|