I have a handfull of comments to make. I hope they are helpful.
First, if($photo1 ne "") isn't very perl-y ... Try if($photo1). There's a lot of differnt kinds of false in perl, undef, and "" are among them.
Second, you should be really careful about embedding filenames in system() calls when they might have been written by some nefarious "customer." If you choose system("rm", "$photo/$cat$id/$thing") (i.e. multi arg call), then you don't have to worry about evil shell escapes. That could save you a lot of trouble one day.
Lastly, your actual question, I think can be solved with opendir:
opendir my $dir, "$photodir/$category" or die "didn't work: $!"; while( my $ent = readdir $dir ) { next unless $ent =~ m/something/; # unlink("$p/$c/$ent") or die "didn't work: $!"; } closedir $dir; }
Probably some people would also recommend File::Find (or a simple glob like the above) — and those solutions may be easier for you, but I like the old fasioned stuff. Actually, having re-read that it's 10 or so images I'd say the glob is probably best.
Update 2 ikegami: In point of fact, I usually use a variant of if(defined $something) myself. I objected to ne "" without thinking it through clearly.
-Paul
In reply to Re: Removing Multiple Image Files
by jettero
in thread Removing Multiple Image Files
by lisaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |