how do i get a KEY based on a VALUE in Perl using hashes?
if i have:
"dime"=>"4"
"nickle"=>"5"
"quarter"=>"2"
"dollar"=>"6"
now I sort them and highest is 6. I wanna be able to grab “dollar”. Here is what i tried:
# sort money based on count
my @sorted = sort {$deposit->{$b} cmp $deposit->{$a}} keys %$deposit;
my %rhash;
@rhash{values %deposit} = keys %deposit;
$owner = $rhash->{$sorted[0]}; #get highest count
If your values are unique, you can reverse the map thus:
[assuming that
$depositis a reference to the hash listed]