http://qs321.pair.com?node_id=855815

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!
I have this array with dates but having problems with my sort code, here is an example about what its goign in on:
#!/usr/bin/perl user strict; my @dates = ('10/02/2004', '02/01/2004', '01/02/2004', '01/06/2004', ' +01/02/2005', '01/12/2004', '08/18/2010'); my @ordered = sort { &compare } @dates; sub compare { $a =~ /(\d{2})\/(\d{2})\/(\d{4})/; $c = $3 . $1 . $2; $b =~ /(\d{2})\/(\d{2})\/(\d{4})/; $c = $3 . $1 . $2; $c <=> $d; } print "@ordered\n";

I got this:
08/18/2010 01/12/2004 01/02/2005 01/06/2004 01/02/2004 02/01/2004 10/02/2004

This date "01/02/2005" is off, I guess the sorting is not reaching the years, any suggestions? Thanks for the help!