in reply to Directory creation in Perl using mkdir

You can try to call mkdir first, then check for the existence:
my $error; mkdir $path or $error = $!; unless (-d $path) { die "Cannot create directory '$path': $error"; }

That should avoid race conditions in directory creation.

Replies are listed 'Best First'.
Re^2: Directory creation in Perl using mkdir
by rovf (Priest) on Apr 04, 2011 at 09:44 UTC
    Why do you need the variable $error? Can't you simply say:

    mkdir $path; die "Cannot create directory $path : $!\n" unless -d $path;

    ? From what I see from the documentation, the -d operator doesn't change $!, does it?
    -- 
    Ronald Fischer <ynnor@mm.st>