I usually use something like
my $dir="/path/to/dir";
opendir(DIR, $dir) or die "can't open $dir: $!";
my @files = readdir DIR;
closedir DIR;
or sometimes I use glob, but anyway, I always need to add a line or two to filter out . and .. which is quite annoying.
How do you usually go about this common task?
I will normally use the
globmethod:This works fine unless the directory has lots of files in it. In those cases you have to switch back to
readdirin awhileloop (puttingreaddirin list context is just as bad as theglob):Often though, if I am reading a bunch of files in a directory, I want to read them in a recursive manner. In those cases I use
File::Find: