You're almost there. There are a few different approaches you can take to get the rest of the way.

The simplist is to store a reference to a list in the existing lists (thus creating an array-of-arrays. In this case, you wouldn't need to modify your current sort lines. However, it would change the layout of your datastructure, so other code will probably have to change.

The second way is to use a Schwarzian Transform, which pulls the data apart before it gets to sort and then puts it back together. It looks like this:

my @sortedComplete = map { $_->[0] } sort { $a->[0] <=> $b->[0] } map { [ $_, (split /\t/, $_)[3] ]} @complete; # Do the same for @progress

The third solution is the GRT, which is conceptually similar to the Schwartzian, but is a bit faster. The difference is that in teh Schwartzian, you pull the data into a seperate portion of a temperary data structure, but in the GRT, you keep everything in the same string. This means you can make use of Perl's built-in sorting subroutine, which is implemented in C and will likely be much faster than calling the Perl block. It looks something like this (totally untested):

my @sortedComplete = map { join "\t", (split/\t/)[1,2,3,0] } sort map { join "\t", (split/\t/)[3,0,1,2] } @complete; # Do the same for @progress

The trick here is that the field you want to sort on goes first in the string. Note, though, that if two dates are the same, they'll be sorted based on the characters following the date.

----
I wanted to explore how Perl's closures can be
manipulated, and ended up creating an object
system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.