http://www.perlmonks.org?node_id=168875


in reply to Problems with -filetest on readdir results

#!/usr/bin/perl use strict; use warnings; my $path="/foo/bar/"; opendir (DIR, $path) or die "Could not open directory: $!"; @files = readdir(DIR); foreach my $file (@files) { print "$file\n"; }
Your foreach loop was incorrect. Use of strict and warnings also helps spot errors.
You could also replace the foreach loop with a map statement:
print map {$_ = "$_\n";} @files;
Cheers!

BazB.

Update: I ignored the -d test, and obviously don't know my foreach loop from my elbow. Oops. ides++ and boo_radley++