This is just screaming out for a Schwartzian transform... ;-) Oh, and for using Text::CSV or something similar.

@out1 = map { $_->[1] } sort { $a->[0] cmp $b->[0] } map { my @d = split /,/; [ join('\0', @d[7,8,0]), $_ ] } @data;

That's just to get it to be efficient.

To get it do anything else, I'm going to concentrate on the last map (which is the first one executed): map { my @d = split /,/; [ join('\0', @d[7,8,0]), $_ ] }.

To sort on weekday order by day of week, we need to know what the order is. Say you have another array elsewhere (associative array, aka hash):

my %dow = qw(Sunday 0 Monday 1 Tuesday 2 Wednesday 3 Thursday 4 Frid +ay 5 Saturday 6);
The numbers give a sort order. You can change the numbers to give any sort order you want. Note that the way this is set up, we're actually sorting alphabetically (using cmp) not numerically, so using letters such as a, b, c, d, e, f, g might be more obvious. Then the map looks something like this:
map { my @d = split /,/; [ join('\0', $dow{$d[7]}, @d[8,0]), $_ ] +}

For splitting the time - I'll leave that as an excersise for you to do - I think this should give you way more than enough direction.


In reply to Re: Sort questions by Tanktalus
in thread Sort questions by wube

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.