Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^2: Finding oldest file in directory

by pg (Canon)
on Oct 18, 2004 at 18:38 UTC ( #400271=note: print w/ replies, xml ) Need Help??


in reply to •Re: Finding oldest file in directory
in thread Finding oldest file in directory

"it'd be faster to cache your stats for the sort"

Depends on what does "oldest" mean, and how files are created, modified and removed from the directory. The catched info might not be correct and useful. It probably just increases the complexity of the program, with 10+ files in the directory, most likely not worth it.


Comment on Re^2: Finding oldest file in directory
Re^3: Finding oldest file in directory
by halley (Prior) on Oct 18, 2004 at 18:41 UTC
    I think what Randal L. Schwartz was referring to, when he said "cache it for the sort," was to use a very common sort optimization technique called, not coincidentally, the Schwartzian Transform.
    @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, (-s $_) ] } @unsorted;

    --
    [ e d @ h a l l e y . c c ]

Re^3: Finding oldest file in directory
by Fletch (Chancellor) on Oct 18, 2004 at 18:58 UTC

    If the underlying files are changing quick enough that -s isn't going to return the same result you're probably already screwed (and I want to say that some qsort implementations might even core on you)).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2014-09-23 19:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls