in reply to Re^4: Find images regardless of filetype extension.
in thread Find images regardless of filetype extension.
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/
Are you a Linux user in Lebanon? join the Lebanese GNU/Linux User Group.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: Find images regardless of filetype extension.
by zzspectrez (Hermit) on Aug 01, 2005 at 14:15 UTC | |
by Chady (Priest) on Aug 01, 2005 at 20:09 UTC | |
by zzspectrez (Hermit) on Aug 02, 2005 at 05:10 UTC |
In Section
Cool Uses for Perl