Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by anonymized user 468275 (Curate)
on Aug 16, 2005 at 12:52 UTC ( [id://484144]=note: print w/replies, xml ) Need Help??


in reply to How to list files in dir with respect to time ?

To crush it down to a one-liner, using glob seemed fastest the most apt:
perl -e 'print "$_\n" for ( sort { -M $a <=> -M $b } glob "/path/\*" ) +;'
Update: by fastest I was thinking about coding effort rather than meaning to suggest a specific focus on performance.

One world, one people

Replies are listed 'Best First'.
Re^2: How to list files in dir with respect to time ?
by Roger (Parson) on Aug 16, 2005 at 15:17 UTC
    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 ... )


      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://484144]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-24 07:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found