If I do this...It works for me. Are you sure you know what $ENV{HOME} resolves to? ? What version of OS X are you running? What version of perl? I'm running 10.2 with the stock perl.
#!/usr/bin/perl
$dir = "$ENV{HOME}/";
opendir DIR, $dir ;
for (readdir DIR) {
-d and print "$dir$_$/"
}
....I aim to get all the files in my home directory that are directories, but the result is a list of only a few of the existing directories:
How do I get a list of all directories in a directory and, more to the point, what is the best way to get a complete tree starting from a certain directory?'Best' depends on what you're trying to do. The File::Find method posted earlier is a good one, yours is a good one (that should work). You might prefer the File::Find method if you're planning on using your script on a variety of platforms and machines, as it will be less dependant on platform specific conditions. You might prefer your solution (if it worked for you) if you were in a high performance environment and needed every possible last cycle you could get, or in an environment where you want to keep your perl installation as small as possible and didn't want to add File::Find (although it's part of the core install, I b'lve)
-Jeff Lowrey