Yes, and strategy is the name of the game.

You tend (%90+ time) to "shoot yourself in the foot" when you try to do too many things at once (like run a marathon, whilst talking on your cellphone, and balancing a book on your head, with your pants around your ankles, orr, drive whilst carrying on a conversation with someone in the back seat and someone on the phone, all whilst eating a giant sandwich)

So, what you want to do, what you need to do, if you wish to be able to walk after you run your program, is gather a list of the files in whatever directory you wish to play in, and this can be accomplished using File::Find or simply with the readdir function (I suggest File::Find if you need to recurse infinetly deep... for most situations)

After you have a list of *potential* deletion candidates, you need to weed out the ones you want (or if it's easier, the ones you wish to keep).

You can either push the qualifying candidates onto an array, and unlink all of them at once, or just delete them when you detect one.

I'd personally use File::Find for the job, and *qualify* and unlink a candidate in one function (commonly called &wanted), especially if you got lots of subdirectories and stuff (cause if you don't have a *full* path, you have to chdir, which File::Find does for you).

Here is some authentic looking pseudocode.

#!/usr/bin/perl -wT use strict; use File::Find; undef %ENV; &find(\&wanted,'/some/path/stuff'); print "all done\n"; exit(1); ## s u b l a n d sub wanted { my $fn = $_; # filename if ( -f $fn) # it's a file { if ( /somepattern/ and /somepattern/ and not /somepatter/) { printf "unlinking $fn (1 == success) ... %s\n", unlink $fn; } } }

 
___crazyinsomniac_______________________________________
Disclaimer: Don't blame. It came from inside the void

perl -e "$q=$_;map({chr unpack qq;H*;,$_}split(q;;,q*H*));print;$q/$q;"


In reply to (crazyinsomniac: strategy) Re2: unlinking multiple files at once by crazyinsomniac
in thread unlinking multiple files at once by krose

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.