Harry Putnam wrote:
I want to do something like this but with perl:
rm -f $(ls -lt|sed -n '6,$p')
so that the five newest files are always left.
Is there some short way to get that effect in perl?
Or do I have to analyze each file with stat or something?
Assuming that you are on a *nix platform, I suggest that you make use of
the ls command with the Perl qx// operator.
my $dir = '/some/dir';
chomp( my @files = qx(ls -t $dir) );
foreach my $file ( @files[5 .. $#files] ) {
unlink "$dir/$file" or die $!
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/