in reply to Sorting by Date Help!

$$a{submitted} <=> $$b{submitted};

<=> does numeric comparison, so your code will only compare by the first number in the string. Transform your data into a format like 08-02-28, then you can use simple string comparison to get correct date comparison.

Replies are listed 'Best First'.
Re^2: Sorting by Date Help!
by Anonymous Monk on Mar 17, 2009 at 18:48 UTC
    Still did not work, but another question to try to simplify what I am asking is if a had a Array of Hashes, like:

    my @data; push @data, {name => "Submitted", date => 01/03/08 }; push @data, { name => "Submitted", date => 04/04/09 }; push @data, { name => "Submitted", date => 12/01/08}; push @data, { name => "Submitted", date => 12/01/09}; push @data, { name => "Submitted", date => 08/10/08}; my @sorted = sort { $a->{date} <=> $b->{date} } @data;

    Would that sort by the most recent date?
      Still did not work

      In what way? I'm surprised... show us what code you've tried, so that we can tell you what's wrong and how to fix it.

      push @data, {name => "Submitted", date => 01/03/08 };

      If you write 01/03/08 it will complain with Illegal octal digit '8' at.

      Would that sort by the most recent date?

      No, because you still haven't fixed the comparison semantics.

        I tried like that and did not get the dates in the order of the most recent dates on top.
        my @data; push @data, {date => '01-03-08'}; push @data, {date => '04-04-09'}; push @data, {date => '12-01-08'}; push @data, {date => '12-01-09'}; push @data, {date => '08-10-08'}; my @sorted = sort { $a->{date} <=> $b->{date} } @data; foreach my $res(@sorted) { print $res->{ date }."\n\n"; }