http://www.perlmonks.org?node_id=242450


in reply to How do I find directories within directories using : parse_dir(`ls -l`)

You could hand-roll it as follows.

Use ls to get a list of directories...

chomp (my @dir = `ls $path`);
...and then test each entry to see whether it is a directory:
my @list_of_directories = grep { -d "$path/$this_entry" } @dir;

Replies are listed 'Best First'.
Re: Answer: How do I find directories within directories using : parse_dir(`ls -l`)
by jasonk (Parson) on Mar 12, 2003 at 18:18 UTC

    This is far from the "best" way. A much shorter (and less resource intensive, and more portable) method is:

    my @list_of_direcories = grep(-d, <$path/*>);

    We're not surrounded, we're in a target-rich environment!
      ...but the original poster said they had to use "ls".