...but just in case you were insane enough to create it, it might look something like this:
(Yep, I tested it...)#!/usr/bin/perl -w use strict; use warnings; sub funky_make_tree { my $tree_hr = shift or return; for my $dirname (keys %{$tree_hr->{"dirs"}}) { print "Creating dir: ", $dirname, "\n"; mkdir $dirname; chdir $dirname; &funky_make_tree($tree_hr->{"dirs"}{$dirname}); print "Done with dir: ", $dirname, "\n"; chdir ".."; } for my $filename (@{$tree_hr->{"files"}}) { print "Creating file: ", $filename, "\n"; open OUT, '>', $filename or die "ARGH!"; print OUT $filename, "\n"; close OUT; } } my %structure = ( dirs => { albemarle => { dirs => { chatauqua => {}, cattaraugus => {}, }, files => [ qw( washington adams jefferson ) ], }, beverly => { dirs => { ataturk => {}, bonaparte => {}, }, files => [ qw( madison monroe jackson ) ], }, cortelyou => { dirs => { peoria => {}, paducah => {}, }, files => [ qw( vanburen harrison tyler ) ], }, }, files => [ qw( alpha beta gamma ) ], ); &funky_make_tree(\%structure);
Update: And I was a bit slower on the draw than Grandpops....
--roboticus
In reply to Re: Recursive mkdir: is there already a module for this?
by roboticus
in thread Recursive mkdir: is there already a module for this?
by jkeenan1
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |