I appreciate that you're just using "mkdir -p" as an example here... but for any passers by who are hunting for a way to make a path of directories they would be better following
blue_cowdawg's advice in
Re: "mkdir -p" equivalent? and using mkpath in
File::Path
If they have a reason they can't use File::Path (even though it's a core module these days) they would be better using the built-in mkdir than shelling out to a system one.
use strict;
use warnings;
my $seperator = '/'; # Change this for a non-Unix compatible OS
my @dirs = ("some/long/dir/path");
for my $path ( @dirs ) {
my @path = split($seperator, $path);
my $cat_path;
for my $dir (@path) {
$cat_path .= $dir;
unless ( -d $cat_path ) {
mkdir ( $cat_path ) ||
die "Can't mkdir '$cat_path': $!\n";
print "mkdir: created directory `$cat_path'\n";
}
$cat_path .= $seperator;
}
}
and
Three has dealt with some of the problems faced by Windows users in
Re: Perl API that emulates mkdir -p on unix? (yes, for *Windows*) :o)