Exactly!
Reading a file or directory alters the system by incrementing pointers: it's best to read only once, but if you read more than once, at least limit your reads to once place.
This sort of thing is exactly why I started reading like this:
my $path = "/path/to/whatever";
opendir (DIR, $path) or die "Can't read $path: $!";
my @files = grep { not /^\.{1,2}$/ } readdir (DIR);
closedir (DIR);
print join("\n", sort @files), "\n";
|