in reply to Dumb recursive mkdir question...

I can't believe that nobody recommended File::Path:

use File::Path qw( mkpath ); mkpath( "/usr/local/foo/bar" ); # die()s on error

- tye        

Replies are listed 'Best First'.
Re^2: Dumb recursive mkdir question...
by grinder (Bishop) on Oct 23, 2007 at 07:51 UTC
    mkpath( "/usr/local/foo/bar" ); # die()s on error

    With the new version of File::Path, you can stop things from dieing quite nicely:

    mkpath("/usr/local/foo/bar", {error => \my $err});

    This new version is bundled with 5.10, and will probably wind up in 5.8.9 as well.

    • another intruder with the mooring in the heart of the Perl

Re^2: Dumb recursive mkdir question...
by tuxz0r (Pilgrim) on Oct 23, 2007 at 02:58 UTC
    I'm almost with gamache on this one, if it's not something you need to do often in the program, or if you don't have the access/ability to install the File:Path module, then doing 'mkdir -p' in a "perlish" way might be even easier (considering you're in a Unix environment):
    $path = "/path/to/real/deep/folder"; $out = `mkdir -p $path 2>&1`; die "Can't make path: $out\n" if ($? > 0);