in reply to Directory Recursion Disorder

Given that your directory structure is only 2 levels deep, there is no need for recursion. You can build your Hash of Arrays in one line.

my %dirs = map{ $_ => [ map{ m[.*/(.*?)$] } glob "$_/*" ] } grep{ -d } glob "/basedir/*";

The main advantage is that you build the datastructure you want directly, but I'm also not much of a fan of the Find::File* stuff.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Replies are listed 'Best First'.
Re: Re: Directory Recursion Disorder
by Anonymous Monk on Jun 24, 2003 at 04:14 UTC

    Thanks. This looks like what I was looking for. I'll just make sure I understand it:

    Pseudo-code:

    use glob to expand filenames in /basedir use grep to grab all directory names for each directory name grab its subdirs pass them onto map to where there matched to the regex '.*/(.*?)$' assign the (array) result from the map to the corresponding %dir key

    I think I've got the basic idea of it, could someone explain how the subdir keys are assigned in the hash in a bit more detail? Thanks :)