I was aware that there had to be a better way to end up with both @files, @dirs with one test but was and still am unsure how to do it. What do you suggest? Really... I was hopping for some code suggestions/improvements
here's one way to do it:
# your version
# my @tmp = readdir(DIR);
# my @files = map { "$dir/$_" } grep { !/^\.{1,2}$/ && -f "$dir/$_" }
+@tmp;
# my @dirs = map { "$dir/$_" } grep { !/^\.{1,2}$/ && -d "$dir/$_" }
+@tmp;
# another version
my @files;
my @dirs;
my @tmp = grep { ! /^\./ } readdir DIR; # grep once.
foreach (@tmp) {
if ( -d "$dir/$_" ) { # stat once.
push @dirs, "$dir/$_";
} else {
push @files, "$dir/$_";
}
}
He who asks will be a fool for five minutes, but he who doesn't ask will
remain a fool for life.
Chady | http://chady.net/