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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.