Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: Directory creation in Perl using mkdir

by lancer (Beadle)
on Apr 04, 2011 at 13:24 UTC ( #897323=note: print w/replies, xml ) Need Help??

in reply to Re^2: Directory creation in Perl using mkdir
in thread Directory creation in Perl using mkdir

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.

  • Comment on Re^3: Directory creation in Perl using mkdir

Replies are listed 'Best First'.
Re^4: Directory creation in Perl using mkdir
by cdarke (Prior) on Apr 04, 2011 at 14:16 UTC
    I see what you mean, but personally I would see errors in Perl on such basic and well-used build-ins would be unlikely. If it was a subtle timing issue then it is possible that a shell would appear to solve it because it would probably take longer. mkdir(1) is not a shell built-in normally (it might be on recent versions of ksh), so that would invoke two child processes just to run one kernel API call. A bit of an over-kill.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://897323]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2018-05-26 08:33 GMT
Find Nodes?
    Voting Booth?