I want to compare the values of the same key in a hashmap. I would like to compare and get the most recent date of the same key. It returns the last date that appears in the hashmap. I want to compare and get the most recent date even if it appears in first in the hashmap. When the same key appears a second time in a hashmap, I'm struggling to compare the second date to the first date when the key appears.
Here is my code :
use strict;
use warnings;
my %hash = ( 48487 => '05/05/19',
52327 => '05/05/23',
123 => '06/01/01',
52327 => '07/08/24',
123 => '07/08/02',
44147 => '24/12/18',
48487 => '05/05/18',
44147 => '24/12/19',
64998 => '05/11/25',
52327 => '05/06/24',
64998 => '05/05/24' );
foreach ( sort { $hash{$a} cmp $hash{$b} } keys %hash) {
print "Date:$hash{$_}\tKey:$_\n";
}