I have an array of directories. I want to iterate over the array and perform mkdir on it:
foreach my $dir (@dirs) {
print $fh "mkdir -p $dir\n";
}
I want to reduce the amount of chars in the file. So I want to use the special case of mkdir which allows to use {name,name,name} and it will create all of them. So for example, instead of:
mkdir -p /a/b/c/e/f
mkdir -p /a/b/c/e/g
mkdir -p /a/b/c/e/h
It will do:
mkdir -p /a/b/c/e/{f,g,h}
The dirs are already in their canonical mode so realpath is not required here.
What would be the best way to iterate over the array @dirs and do this? I think I need to use dirname on each one and then collect every "collection" and then do mkdir on it. But what is the best way to do it?