Win has asked for the wisdom of the Perl Monks concerning the following question:
Can anyone suggest a Perl script that will check the number of files in a folder and delete the oldest two files, if there are more than 20 files present in the folder?
Somebody has kindly given me the following bit of code:
Can anyone please expand this? Perhaps a detailed explanation. Or suggestions for improvement.opendir my $d, $dir; my @f = sort { -M $b <=> -M $a } readdir $d; unlink @f[-0,1] if @f > 20;
Back to
Seekers of Perl Wisdom