in reply to Sorting Array of dates in PERL

The DateTime module overloads the string/numeric comparison operators ('<=>' and 'cmp'), so if you can get them into DateTime objects instead of strings, you can use a trivial sort operation (my @sorted_dates = sort { $a <=> $b } @unsorted_dates;.

Otherwise, if you store them in DDMMYYYY format, you can do the same thing (or use 'cmp' if you have slashes in the date). Personally, I prefer to use DateTime since I don't want to be constrained by a specific format.

----
send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.

Replies are listed 'Best First'.
Re^2: Sorting Array of dates in PERL
by meetraz (Hermit) on Jun 28, 2004 at 21:15 UTC
    don't you mean YYYYMMDD format? I don't think DDMMYYYY would sort properly.

      Ahh, yes, you're right.

      And getting details like this wrong is exactly why you should just use DateTime :)

      ----
      send money to your kernel via the boot loader.. This and more wisdom available from Markov Hardburn.