I have a problem regarding deletion of files in Perl. I want to delete all files within a folder with the extension .log. Is there a smart way to do this in Perl?
I haven't got much experience coding perl.
I have a problem regarding deletion of files in Perl. I want to delete all files within a folder with the extension .log. Is there a smart way to do this in Perl?
I haven't got much experience coding perl.
Fast and dirty: unlink glob('*.log');.
I'd recommend manual loop with opendir/readdir over directory for more control though.
I like Oleg's, it's mad short. I usually hack up something like:
$ perl -e 'foreach my $f (@ARGV){ print `ls -l $f`; unlink $f }' *.log
-rw-r--r-- 1 The Genius None 0 Jun 21 06:15 bar.log
-rw-r--r-- 1 The Genius None 0 Jun 21 06:14 foo.log
Cause I can't remember all the commands and it's ease to add in tests and regexes. Also this prints out some indication of what it did. Choose your coffee.