in reply to Deleting Oldest Logfiles

Also, you use my $LOGSIZE inside of your loop. This temporary variable goes away in each loop iteration, leaving you with the same outer value on each iteration.

It might be a little more efficient to do something like:

open LIST, "ls -1t $LOGSTR |" or die "could not ls: $!"; my @Files = <LIST>; close LIST:
Then you have the list to delete in sorted order, and you can unlink them as needed. It should be more efficient

Replies are listed 'Best First'.
Re^2: Deleting Oldest Logfiles
by kyle (Abbot) on Oct 22, 2008 at 15:42 UTC

    Don't forget to chomp the incoming list. Also, if all you do is read the results immediately and use them directly, backticks are simpler.

    chomp( my @Files = `ls -1t $LOGSTR` ); die "No files?" if ! @Files;

    I agree with the idea of using ls to get a sorted list of files. It's a lot easier than a manual stat and sort (though there's probably a module to do it for you).