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/$_"; } }
In reply to Re^5: Find images regardless of filetype extension.
by Chady
in thread Find images regardless of filetype extension.
by zzspectrez
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |