in reply to •Re: Keeping only the $n newest files/directories in a diretory?
in thread Keeping only the $n newest files/directories in a diretory?

(ST)

Is the ST really worth the effort here? On my system, in a directory with 20000 files, there is no noticable difference between

my @newest_first = map $_->[0], sort { $a->[1] <=> $b->[1] } map [$_, -M], <*>;
and
my @newest_first = sort { -M $a <=> -M $b } <*>;
while the first one took me much longer to type in.

Most directories on my systems don't even have twenty thousand files :)

Juerd
- http://juerd.nl/
- spamcollector_perlmonks@juerd.nl (do not use).

Replies are listed 'Best First'.
Re: Re: &bull;Re: Keeping only the $n newest files/directories in a diretory?
by halley (Prior) on Apr 19, 2003 at 13:45 UTC

    Is the ST really worth the effort here?

    I can understand the "premature optimization" argument here, but I can also understand it if merlyn (Randal Schwartz) types the top two lines of this optimization in his sleep, or at least with a single keystroke. ;)

    While the /proc filesystem is not actually a filesystem as such, and a clone in /var would probably not have -M issues, either, the same pruning script would be useful in many different circumstances. If trying to run it on a slower link, such as an SMB mounted share across the corporate campus, on a per-hour cron job, I'd definitely want such an optimization.

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

      I can also understand it if merlyn (Randal Schwartz) types the top two lines of this optimization in his sleep

      So do I. Which is the reason I commented. Yesterday someone said the same thing to me about another ST: is it really worth the effort and memory usage? What he said made sense: an ST uses a lot of memory and in many cases the win is too small to be relevant.

      If trying to run it on a slower link, such as an SMB mounted share across the corporate campus

      You may be right about this one. I don't know how SMB is implemented and whether any client side caching is (can be) done.

      a per-hour cron job

      In a per-hour cron job it doesn't matter. Even in a per-minute cron job, I'd argue that the difference between half a second and half a second is very small :)

      Juerd
      - http://juerd.nl/
      - spamcollector_perlmonks@juerd.nl (do not use).