Question: I am trying to find out maximum value in a hash and corresponding key to that maximum value. My hash looks like 

```
%hash = (
    bob => "4.9",
    gita => "3.9 , 6.8",
    diu => "3.0",
);

```

Now I want to find the maximum value in that hash with the key it belongs. 

Output needed is 

```
gita 6.8  

```

I am trying to sort the values in `%hash` in ascending order to get the maximum value like this 

```
sub hashValueAscendingNum {
    $hash{$a} cmp $hash{$b};
}

foreach my $highest (sort hashValueAscendingNum(keys(%hash))) {
    print "\t $hash{$highestMagnitude} \t\t $highest \n";
}

```

I want all the values in the hash to be checked, and the one with maximum value should be returned with its key. 

How can i do that?

Answer: 
A hash has only a single key and a single value, and each key must be unique. In your original problem you have this:

```
%hash = (
   bob => "4.9",
   gita =>"3.9 , 6,8",
   diu => "3.0",
);

```

Well, `gita` can't have two values. Nor, can you have two keys in your hash equal to `gita`. Thus, you can't use a simple hash to store your values.

There are ways around this though by using references. For example, each element in your hash can contain a [reference to an array](http://perldoc.perl.org/perlreftut.html). Thus, your data structure can look like this:

```
%hash = (
    bob =>  [(4.9)],
    gita => [(3.9, 6.8)],
    diu  => [(3.0)],
);

```

The `[` and `]` marks a reference to an array. 

However, this wouldn't really solve your particular problem since you now have to go through each key in the hash, then each element in the array for each key, and sort those. You could create a sorting subroutine, but just because you can say `sort` doesn't make it efficient.

Maybe what you need is an array of arrays. This will get rid of the issue you have with `gita` having two values, but make sorting a bit easier. Imagine a structure like this:

```
my @array = (
    [bob  => 4.9],
    [gita => 3.9],
    [gita => 6.8],
    [diu  => 3.0],
);

```

Now, we can do a sort on `@array` depending upon the value of `$array[$x]->[1]`! All we need is for each element of the array `@array` is to compare $a->[1] with $b->[1]. Then, if we do a reverse sort on it, the biggest element will be `$array[0]`. The name is `$array[0]->[0]` and the element is `$array->[0]->[1]`.

```
#! /usr/bin/env perl
use strict;
use warnings;
use feature qw(say switch);

my @array = (
    [bob  => 4.9],
    [gita => 3.9],
    [gita => 6.8],
    [diu  => 3.0],
);

@array = reverse sort mysort @array;

say "$array[0]->[0] $array[0]->[1]";

sub mysort {
    $a->[1] <=> $b->[1];
}

```

And the output is:

```
gita 6.8.

```

You notice that link to [Perldoc's perllol](http://perldoc.perl.org/perlreftut.html)? I suggest you read it if you've never worked with Perl references before.
You got several good answers. Now a bad one (assuming you fix the decimal separator in the hash):

```
my %hash = (bob => "4.9",
            gita =>"3.9 , 6.8",
            diu => "3.0",
            );

my $max = (map{join" ",@$_[0,1]}sort{$b->[1]-$a->[1]}map{[$_,sort{$b-$a}split(/ , /,$hash{$_})]}keys%hash)[0];

print "$max\n";

```

Output:

```
gita 6.8

```

Never do this unless you're deliberately trying to golf and/or obfuscate it though.