in reply to Re: if (-d$_) failes because of white space
in thread if (-d$_) failes because of white space

opendir DIR,$dir or die "Can't open directory.\n"; @dir = readdir DIR; ... foreach(@dir) { if (-d$_) {print $_," is a directory.\n";} elsif (-f$_) {print $_," is a file.\n";} else {print $_," is not a file or a directory!\n";} }

readdir() gives you directory entries without the path component. So you have to either chdir() into the directory before your foreach loop, or write

foreach(@dir) { my $path = "$dir/$_"; # prepend dir if (-d $path) {print $path," is a directory.\n";} elsif (-f $path) {print $path," is a file.\n";} else {print $path," is not a file or a directory!\n";} }