Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Answer: How do I find directories within directories using : parse_dir(`ls -l`)

( #242450=categorized answer: print w/ replies, xml ) Need Help??

Q&A > directories > How do I find directories within directories using : parse_dir(`ls -l`) contributed by Codmate

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;

Comment on Answer: How do I find directories within directories using : parse_dir(`ls -l`)
Select or Download Code
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".
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-08-01 02:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (285 votes), past polls