in reply to Re: Sorting a slurped file by a date field
in thread Sorting a slurped file by a date field

I am expecting each row in the array to contain "$status\t$reference\t$project\t$created\n"

The array has 96 rows so far and each row has four elements tab separated.

Here I am slurping the entire file into an array.
open (LINKS, "$linksQuery") || die ("Can't open $linksQuery: $!"); my @links = <LINKS>; close (LINKS);
I take it one step further by separating this one array into two arrays based off of $status.
for (@links) { chomp($_); my ($status, $reference, $project, $created) = split(/\t/, $_); if ($status eq "Completed") { push(@complete, $_); } else { push(@progress, $_); } }
After I have these two arrays I want to sort each in most recent to latest order. I used the other response to my post, which did sort both arrays but "12/13/02 09:42:51 CST" happens to appear before 12/05/02 13:19:50 CST when it should be the other way around.

I hope that I made things sound a little more clearier with this explanation.

Thanks for you help again, Bionicle32

Replies are listed 'Best First'.
Re: Re: Re: Sorting a slurped file by a date field
by ysth (Canon) on Feb 04, 2004 at 01:42 UTC
    Thanks, that's a lot clearer. To sort in descending order, simply replace $a with $b and $b with $a; e.g. in place of { $a->[3] <=> $b->[3] }, use { $b->[3] <=> $a->[3] }.

    I hope your $created's are actual numbers, not strings as you show. If you actually have strings in your data, you are going to have to parse them further, since they won't be easily comparable as is.

      They are strings like I showed in the example you responded too. Is it possible that you could further explain how I would parse them to get the dates sorted in the correct order?

      Thanks,
      Bionicle32