Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How to list files in dir with respect to time ?

by Roger (Parson)
on Aug 16, 2005 at 15:17 UTC ( [id://484170]=note: print w/replies, xml ) Need Help??


in reply to Re: How to list files in dir with respect to time ?
in thread How to list files in dir with respect to time ?

You could use the Orcish Maneuver to make your code go faster...

# Original code for ( sort { -M $a <=> -M $b } glob ... ) # Orcish Maneuver my %t; for ( sort { ($t{$a} ||= -M $a) <=> ($t{$b} ||= -M $b) } glob ... )


Replies are listed 'Best First'.
Re^3: How to list files in dir with respect to time ?
by anonymized user 468275 (Curate) on Aug 17, 2005 at 08:36 UTC
    I've looked into this now - I was expecting sort to be smart enough to do that manouvre itself. For those who don't understand what it's doing, it is forcing the sort routine to perform the -M operation only once per file, but at the overhead of a hash lookup per sort iteration (there are geometrically upon n sort iterations per n files). sort + block could be optimised for minimal calculation of each side of the <=> operator (or cmp as appropriate) -- after all it ought to know it's going to be doing that irrespective of what's in the block, so it's a safe optimisation for sort to be doing already. But the orcish manouevre appears to be necessary because no such optimisation has been implemented. Perhaps Sort::Key has the manoeuvre already, however.

    One world, one people

      Perhaps Sort::Key has the manoeuvre already, however

      well, it's not exactly the Orcish manouevre, but Sort::Key calculates every key only once.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://484170]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-26 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found