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..


What have you tried?

Due to the format, using 'sort' is fine.

my %h = ( 48487 => '05/05/18', 52327 => '05/05/23', 123 => '04/01/01');
print 'Sorted=', join(',', sort values %h), "\n";
Sorted=04/01/01,05/05/18,05/05/23

perldoc -f values
perldoc -q "How do I sort a hash"

.



Relevant Pages