in reply to How to get the names of sub-directory in a directory?

If you even want to filter . and .., you could use something like the following:
opendir(DIR, $some_dir) or die "Can't opendir $some_dir: $!"; my @subdirs = (); foreach (readdir(DIR)){ next if /^\.\.?$/; # skip . and .. push (@subdirs, $_) if -d "$some_dir/$_"; } closedir DIR;

Best regards,
perl -e "$_=*F=>y~\*martinF~stronat~=>s~[^\w]~~g=>chop,print"

Replies are listed 'Best First'.
Re: Re: How to get the names of sub-directory in a directory?
by japhy (Canon) on Feb 01, 2002 at 14:48 UTC
    I'll side with merlyn here. Do not use /^\.\.?$/, but rather /^\.\.?\z/, and if you need to know the difference, re-read the regex docs on how the $ and \z anchors differ.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;