Your solution seems a little too clever to me. You're deleting as you go through the tree. I'd break the task into two steps:
- find everything to be deleted;
- second, delete it
So use File::Find (a module whose interface I hate, try
File::Find::Rule instead) to push everything into an array as you find it, then ...
foreach (reverse @array) {
(-d && rmdir) || (-f && unlink)
}
Note the reverse - you'll find parent directories before their contents, but need to delete them afterwards.
Alternatively, if you unshift data into the array, the reverse isn't needed. But IMO pushing is better, as it's more widely used and understood.
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.