On Mon, Jan 12, 2009 at 17:41, Gunnar Hjalmarsson <nore...@gunnar.cc> wrote: > 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. snip
Why? This requirs two external programs to be spawned (a shell and ls), and, as you pointed out, only works on Unix-like machines. It is not that much trouble to do the sort yourself (as my code shows). -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/