@list = (
{fname => 'Jan', lname => 'Krynicky',
birth_date => 'Sep 3 1975', #...
},
{fname => 'Pavel', lname => 'Krynicky',
birth_date => 'Dec 25 1969', #...
},
{fname => 'Martin', lname => 'Krynicky',
birth_date => 'Aug 24 1973', #...
},
);
####
use Date::Calc qw(Decode_Date_US);
use Data::Dumper;
sub convertdate {
return sprintf '%04d%02d%02d', Decode_Date_US($string)
}
# ST
@sorted = map{
$_->[1]
} sort{
$a->[0] <=> $b->[0]
} map{
[ convertdate($_->{birth_date}), $_ ]
} @list;
print Dumper(\@sorted);
# @keys array
{
my @keys = map convertdate($_->{birth_date}), @list;
@sorted = @list[ sort {$keys[$a] cmp $keys[$b]} (0..$#list) ];
}
print Dumper(\@sorted);
# GRT
@sorted = map{
## Chop off the bit we added.
substr( $_, 8 )
} sort map{ ## Note: No comparison block callback.
## Extract the field as before, but concatenate it with the original element
## instead of building an anonymous array containing both elements.
convertdate($_->{birth_date}) . $_
} @list;
print Dumper(\@sorted);
####
$VAR1 = [
'HASH(0x18db494)',
'HASH(0x224e9c)',
'HASH(0x224fa4)'
];