When you're writing something that could do some lasting damage, it's always best to test it first. I've learned to be a bit paranoid, especially when running my own code, so more often then not I end up doing something like:
my $still_testing = 1;
my $talkative = 1;
foreach my $to_delete (@liberation_pool)
{
print "Deleting $to_delete\n" if $talkative;
unlink ($to_delete) unless $still_testing;
}
Look over the output and make sure things add up. As in, it's not deleting your entire MP3 directory, formatting your filesystem, or stealing food from your fridge. A tiny slip of logic and you could be facing a re-install. Laziness is a virtue, except when you're too lazy to test it properly and it bites you.
Another thing is to not actually delete them, but to move them to some sort of 'orphan' folder (fixing name collisions, of course) which can be discarded at your leasure, much like the trash can/recycle bin. Use
rename instead of
unlink, for example.
rename is dangerous too, since you can rename every single file in a directory to a single file, which 'mv' prevents you from doing in most cases.
There are probably better test techniques than the simple 'printf debugging' described here. Just make sure you can turn on the safety when testing something that could be very dangerous.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.