How about something like:
#!perl -w
use strict;
use File::Find;
my $days = 12 * 7; # twelve weeks, seven days a week.
sub DeleteOldFiles
{
return 0 unless -M > $days;
unlink $_ or die $!;
return 1;
}
find( \&DeleteOldFiles, '.' );
Although I think that also sweeps sub directories too.
Update
Hmmm, File::Find is really for delving into the subdirs, and if you don't want that, then just glob(*) like this:
#!perl -w
use strict;
my $days = 12 * 7; # twelve weeks, seven days a week.
while( <*> )
{
next if -d;
unlink $_ or die $! if -M > $days;
}
By the way, -M returns days since last modified, -A returns days since last accessed. I wasn't sure what your purpose was, but recently accessed files might be useful.
As for speed issues, you have to loop over everyfile, no matter what, the only question is the efficiancy of the loop. Well, do as little as possible in the loop. Calculate the age aforehand, and short circuit where you can.