in reply to Sort questions
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):
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:my %dow = qw(Sunday 0 Monday 1 Tuesday 2 Wednesday 3 Thursday 4 Frid +ay 5 Saturday 6);
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sort questions
by wube (Acolyte) on Feb 01, 2005 at 14:42 UTC |