in reply to Delete files if they match help!
Consider replacing
opendir(DIR,$dir_to_open) || die("Cannot open directory !\n"); @dir_contents= readdir(DIR); closedir(DIR); foreach $file (@dir_contents){ if(!(($file eq ".") || ($file eq ".."))){ # I want to delete the files }
with:
use File::Slurp; for my $file (grep { -f } read_dir($dir_to_open)) { # I want to delete the files }
File::Slurp is a CPAN module which abstracts away all the open/close/checking details and automatically filters out the special 'dot' directories. The grep -f selects only files.
You do use strict and warnings, don't you?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Delete files if they match help!
by Anonymous Monk on Jan 07, 2011 at 15:13 UTC | |
by toolic (Bishop) on Jan 07, 2011 at 18:02 UTC | |
by Anonymous Monk on Jan 07, 2011 at 18:55 UTC | |
by roboticus (Chancellor) on Jan 07, 2011 at 19:38 UTC | |
by Anonyrnous Monk (Hermit) on Jan 08, 2011 at 01:12 UTC | |
by Anonymous Monk on Jan 07, 2011 at 19:51 UTC |