Chas. Owens wrote:
Gunnar Hjalmarsson 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.
Because I'm lazy? ;-) Or maybe because (guess I shouldn't say this since
I don't really know) I suppose that the -t option of ls sorts more
efficiently than Perl's sort() even when you do a Schwartzian Transform.
But in the end it's a matter of taste, isn't it?
--
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/