Thanks, cdarke, I was looking for a way to bring back the result of a shell command with the backtick operator... (and I didn't find it)

So actually it's possible with the system() call.

As for using the shell, it wasn't clear for me what was the original poster's problem with the mkdir() call, what was exactly failing.

It appears to be a race condition from what he described, or it can be something else. By moving out the test of the directory's existance from Perl and into the shell, it's possible to eliminate the possibility of other errors inside Perl. I would have suggested to move out the `mkdir` command to the shell too.

If the problem would still appear when the commands are executed in the shell, then it's not a Perl issue anymore.

On the other hand, if moving out the commands to the shell would eliminate the issue, then it was a problem somewhere inside Perl, but it would be solved.

My bet is that it's a problem with how Perl accesses the filesystem, and the "unless ( -d $dir ) { }" test is failing because it's not picking up the change fast enough (the creation of the dir by the other script instance), so it fails to detect it. Maybe it is some kind of a cache issue. (I have no idea, this is just a guess). But if this is the actual problem, then moving out the commands to the shell would probably solve it... (another guess). If not, then it's probably a real race condition.


In reply to Re^3: Directory creation in Perl using mkdir by lancer
in thread Directory creation in Perl using mkdir by sselva

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.