in reply to (tye)Re: recursive mkdir
in thread recursive mkdir

Thanks for the suggestion. I hadnt come across that module. Ill have to check it out, Im interested how the module does it.

I used recursion, because it was the only obvious way I could think of doing it. One question. How much slower could the code be when dealing with creating subdirectories? Since realisticly you are not going to create directories of say 100 deep. The script Im using it in seems to work quickly.

THANKS!
zzSPECTREz

Replies are listed 'Best First'.
(tye)Re2: recursive mkdir
by tye (Sage) on Jan 08, 2001 at 11:12 UTC

    Yeah, sorry, I was just noticing that you had coded it recursively. I didn't notice the recursion and had interpretted your posting as, in part, asking how you would go about rewriting it recursively (to learn about recursion). :-}

    No, doing this recursively isn't going to make this unacceptably slow. I think the reason that you ended up with a recursive solution is that your first idea at how to loop through the list of directories went in the "wrong" order (or you chose this order because you wanted to be optimistic and assume that most of the time you don't need to create many directories so start from that end).

    Recursion is one way to reverse a loop, but there is usually a "better" way. In fact, in Perl you can use the built-in "stacks" to reverse even the most hard to reverse loop via:

    my @stack; while( <> ) { push @stack, $_; } while( @stack ) { local( $_ )= pop @stack; # your code here }
    And it is hard to argue that the above is worse than recursion in any way. ;)

            - tye (but my friends call me "Tye")