Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: How can I sort this array?

by flounder99 (Friar)
on Jun 17, 2002 at 19:24 UTC ( #175172=note: print w/replies, xml ) Need Help??

in reply to How can I sort this array?

Time::Local is core and faster than Date::* functions

use Time::Local qw( timelocal ); use strict; my @input = reverse qw( Order_29May11:05.bak Order_11Jun20:25.bak Order_10Jun14:16.bak Order_10Jun16:04.bak ); # reversed to prove it works since they are already sorted my @months = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my %months; for (0 .. $#months) {$months{$months[$_]} = $_} # merlyn's definition of the # Schwartzian Transform # changed to numerical sort my @output = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [$_, expensive_func($_)] } @input; print join "\n", @output; exit; sub expensive_func { # convert filename to date $_[0] =~ /Order_(\d+)(...)(\d+):(\d+)\.bak/ or die "bad filename $_[0]"; return timelocal(0, $4, $3, $1, $months{$2}, 0); } __OUTPUT___ Order_29May11:05.bak Order_10Jun14:16.bak Order_10Jun16:04.bak Order_11Jun20:25.bak
-- flounder

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://175172]
[Discipulus]: fibonacci in 34.. uh!!
[choroba]: Without totally changing the approach, I can't squeeze it more.
[Discipulus]: i'm stuck at 54 ;=( but for me is good enough
[Discipulus]: and even if i lead in primality check, i have 2 chars more than you in iEmirp nums..

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2017-10-20 09:20 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (260 votes). Check out past polls.