Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

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

( #788916=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 toolic

Assuming you're using the parse_dir function from the File::Listing module...

The following will populate the @dirs array with the names of the sub-directories in the current directory (excluding all hidden directories which begin with the dot character):

use File::Listing qw(parse_dir); my @dirs = map { my( $name, $type ) = @$_; $type eq 'd' ? $name : () } + parse_dir(`ls -l`);

To include 'dot' directories (except for the special . and .. directories), you'd simply use ls -la:

my @dirs = map { my( $name, $type ) = @$_; $type eq 'd' ? $name : () } + parse_dir(`ls -la`);

Comment on Answer: How do I find directories within directories using : parse_dir(`ls -l`)
Select or Download Code
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 making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2016-02-10 13:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?





    Results (346 votes), past polls