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)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.