system( "rm -rf /path/to/tree" );

[...] But I obviously want to avoid the system call with it's fork.

Good plan. But if, for some strange reason, it is unavoidable, please use the list form of system, i.e. system("/bin/rm","-rf","/path/to/tree") to avoid nasty surprises from the shell.

I'd like to delete a complete path which sits on an NFS export, and the network is slightly unreliable. [...] rm also complains from time to time that the directory is not empty, but at least the script stays alive, and I can retry. It then always succeeds on the second attempt. I never need a third one.

NFS caches some information about non-local files for a while (three seconds by default), without consulting the server. This may confuse the local system. See nfs(5).

Depending on how the NFS export is mounted, access to it may block (hard mount) or fail (soft mount). Again, see nfs(5).

Another funny thing that may happen is that another computer creates files in the directory tree that you are deleting. (Race Condition)

And finally, consider making the network work more reliably.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re: remove_tree dies even when trapped with eval by afoken
in thread remove_tree dies even when trapped with eval by Alphaphi

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.