in reply to Re: Sorting according to date
in thread Sorting according to date

First you assume the date format he is using and then you go on to suggest a byzantine method of sorting dates in that format...

If his dates really are in a format like "DD.MM.YYYY" then Date::Calc is hardly necessary:

my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, join "", reverse (split /\./) ] } @dates;

-sauoq
"My two cents aren't worth a dime.";

Replies are listed 'Best First'.
Re: Re: Re: Sorting according to date
by hipe (Sexton) on Jun 10, 2003 at 11:11 UTC
    I like your solution, it is elegant but a bit slower. Conversion of date strings to integers is expensive, but it pays off in the sorting faze. Dates that are close together have 4 to 6 equal characters from the beginning of the string, and the for loop is also faster than map. I made a couple of benchmarks to verify that. The difference in speed is not significant.
    I had to assume some date format to be able to produce working solution. It is easy to modify for different format.
      Thank you, O enlightened ones.

      Regards

      Campbell