Dir::Purge(3) Purge directories to a given number of files.

OPTIONS

Options are suppled by providing a hash reference as the first argument. The following calls are equivalent:

  purgedir ({keep => 3, test => 1}, "/spare/backups");
  purgedir_by_age ({keep => 3, test => 1}, "/spare/backups");
  purgedir ({strategy => "by_age", keep => 3, test => 1}, "/spare/backups");

All subroutines take the same arguments.

keep
The number of files to keep. A negative number will reverse the strategy. See option "reverse" below.
strategy
Specifies the purge strategy. Default (and only allowed) value is ``by_age''.

This option is for "purgedir" only. The other subroutines should not be provided with a "strategy" option.

include
If this is a reference to a subroutine, this subroutine is called with arguments ($file,$dir) and must return true for the file to be included in the list of candidates,

If this is a regular expression, the file file will be included only if the expression matches the file name.

reverse
If true, the strategy will be reversed. For example, if the strategy is ``by_age'', the oldest files will be kept instead of the newest files.

Another way to reverse the strategy is using a negative "keep" value. This is not unlike Perl's array subscripts, which count from the end if negative.

A negative "keep" value can be combined with "reverse" to reverse the reversed strategy again.

verbose
Verbosity of messages. Default value is 1, which will report the names of the files being removed. A value greater than 1 will produce more messages about what's going on. A value of 0 (zero) will suppress messages.
debug
For internal debugging only.
test
If true, no files will be removed. For testing.