For the recursive mkpath solution:
Of course reading the docs helps.
use strict;
use warnings;
use File::Path;
my $name = shift;
my $branch = shift;
my $depth = shift;
# We really should be checking arguments
# Bad things happen if $branch or $depth is 0
print "Creating directory ",$name," with ",
$branch, " branches to the depth of ",
$depth, "\n";
my $aref = MkTree($name, $branch, $depth, [] );
foreach my $path ( @$aref ) {
print $path, "\n";
}
mkpath($aref, 1, 0777);
exit;
sub MkTree {
my ($name, $branch, $depth, $aref) = @_;
my $start = "a";
foreach my $pos (1..$branch) {
my $let = chr(ord($start) + $pos - 1);
if ( $depth == 1 ) {
push(@$aref, join('/', $name, $let) );
}
else {
MkTree( join('/', $name, $let), $branch,
$depth-1, $aref);
}
}
return $aref;
}