Beefy Boxes and Bandwidth Generously Provided by pair Networks RobOMonk
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

•Re: Finding oldest file in directory

by merlyn (Sage)
on Oct 18, 2004 at 14:25 UTC ( [id://400266]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Finding oldest file in directory

Probably only the teeniest bit faster to run, but a lot easier to type, I would have picked -s $a over (stat $a)[10] and so on.

Also, above some number of files (depending on your OS efficiency), it'd be faster to cache your stats for the sort.

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


update: Darn it. I misread [10] as wanting the size, even though there were other clues in the message about wanting the oldest.

OK, yes, replace -s there with -M.

Replies are listed 'Best First'.
Re^2: Finding oldest file in directory
by pg (Canon) on Oct 18, 2004 at 14:38 UTC
    "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.

      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 ]

      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)).

Re^2: Finding oldest file in directory
by bluto (Curate) on Oct 18, 2004 at 15:15 UTC
    Do you mean '-C' instead of '-s' (file size)?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://400266]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.