That's actually a variant of a technique called the Guttman Rossler Transform; in the GRT you'd encode your times just before sorting, and decode them after you're done. But if you can just keep them in sortable form all along, life is simpler.sub makeEvent { sprintf("%08d\t%s",@_); } @event_queue = (makeEvent($time,"Event 1"), makeEvent($time,"Event 5") +, makeEvent($time,"Event 5")); # now this works fine! @event_queue=sort @event_queue;
The other alternative is the Schwartzian Transform, which is a fraction less efficient, but will still do the job very well...
The trick here is that the time values are extracted, and then compared as integers to get things in the right order. Then the strings that were associated with those integers are returned by the top map call.@event_queue = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [$_, (split/\t/)[0]] } @event_queue;
In reply to Re: Sort routine
by RMGir
in thread Sort routine
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |