Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Finding oldest file in directory

by Eyck (Priest)
on Oct 19, 2004 at 12:36 UTC ( #400494=note: print w/ replies, xml ) Need Help??


in reply to Finding oldest file in directory

Why sort at all?

The problem is to find the oldest file, that's it.

just walk the list of files, and compare every one to the 'currently newest', this would be the most efficient solution.

I'm shocked that people actually suggested Shwartzian Transform and similiarly overgrown solutions to such simple problem.


Comment on Re: Finding oldest file in directory
•Re^2: Finding oldest file in directory
by merlyn (Sage) on Oct 19, 2004 at 13:04 UTC
    Careful. The high-water-mark algorithm is actually slower than sorting to get the highest value, for some small number of items. Think of the few lines of Perl code that would have to be repeatedly executed for each item. Then think of how little work it takes directly in C to sort that list instead.

    Yes, surprising when I first heard it too.

    -- Randal L. Schwartz, Perl hacker
    Be sure to read my standard disclaimer if this is a reply.

      This node was taken out by the NodeReaper on Tue Oct 19 09:28:56 2004 (EST)
      Reason: theorbtwo dupe. Delete this one, not 400505, please.

      For more information on this node visit: this

      Note that the arguments against a perl-based high-water-mark algorithm don't apply to List::Util::max, which, like sort, is written in C. (The overhead of a function call vs the overhead of other opcodes does, however, apply, but that's a very small difference.)

        Yes, I was talking about builtin Perl sort vs a Perl-coded high-water mark. Your List::Util's max doesn't apply in the referenced case (largest file), because max can't be coaxed to doing an indirection, so you'd need a GRT style translation, or else you're back to open coding it, again.

        The point here is that high-water-mark is one strategy, and sorting is another strategy, with different costs depending on the length. The only real takeaway here is Benchmark will know, because you can't always guess.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2014-12-25 13:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls