in reply to Re: noshow by file extension
in thread noshow by file extension
my @unscont = sort grep !/^\.\.?$/ && !/\.gif$/, readdir(DIR);
Bad advice. If that grep !/^\.\.?$/ is there to remove the current and parent directories, it won't always work.
Trying to remove these directories from the output of readdir with a regexp is hard to get right (and when you get it right it's damned ugly). Use procedural code instead. It's clearer and has no borderline cases to trip you up.
my @unscont = sort grep { $_ ne '.' and $_ ne '..' and !/\.gif$/ } readdir(DIR);(Or as part of my push proposition; that shall be left as an excercise to the reader.)my @dirs = grep -d "$directory/$_", @unscont; my @files = grep ! -d "$directory/$_", @unscont;
If you want to separate files and dirs in one pass, you could do something like:
my( @dirs, @files ); push @{ -d "$directory/$_" ? \@dirs : \@files}, $_ for @unscont;
That is, I could admit to doing that, but I'm not sure that it's crystal clear in its intent :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: noshow by file extension
by Aristotle (Chancellor) on Jun 03, 2002 at 21:47 UTC |