Re: how to sort hash by value, where value is a valid date



perl_help_needed wrote:

> Hi all,
> I want to sort a hash by its vlaue in perl. Value is a valid date.
> example:
> key value
> 48487 05/05/18
> 52327 05/05/23
> 64998 05/05/24
> 44147 05/05/18
> ........etc..
> here value can be any valid date in the format yy/mm/dd.
> Could anyone help me out with this one please!!
> Thanks..


You cannot actually sort a hash, but your can access its contents in
specified order in a foreach loop, like this:-


foreach (sort { $hash{$a} cmp $hash{$b} } keys %hash) {
print "Date:$hash{$_}\tKey:$_\n";
}


--
Brian Wakem


.



Relevant Pages