in reply to Sorting Array of dates in PERL


Im assuming your date is in the form mm-dd-yy.

@datesort can contain any text embedded with the date. The below example considers that the line starts of with the digits of the date. You can however modify the regex based on your code.
@datesort = qw(6-1-04 5-4-04 14-21-04 12-3-04); my @data = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { my($m,$d,$y) = /^(\d+)-(\d+)-(\d+)/; [ $_, sprintf "20%d%02d%02d", $y, $m, $d ] } (@datesort); foreach (@data) { print "$_\n"; } ^D 5-4-04 6-1-04 12-3-04 14-21-04