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:
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]);
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. :)