in reply to noshow by file extension
Note the use of grep to sort out all entries consisting of a single or double dot and those ending in .gif right off the bat, then shuffling it through sort so that you don't have to call sort twice to sort the lists of files and directories individually. You can also write that separation into @files and @dirs as (/\./ ? push @files, $_ : push @dirs, $_) for @unscont;thus finishing the job with a single pass through the list. Lastly, /\./ is a really lousy form of checking for directories because who's to say a file has to have a dot in its name, or that a directory cannot have one? Instead, use the -d operator as inopendir(DIR, $directory) || die print "Couldn't open directory"; my @unscont = sort grep !/^\.\.?$/ && !/\.gif$/, readdir(DIR); closedir(DIR); @files = grep(/\./, @unscont); @dirs = grep(!/\./, @unscont); for my $file (@files) { print qq[ <a style="{font-size: 13px; color: #000000;"} href="./$ +this?func=read&file=$file&dire=$dire">$file</a><br>\n]; }
(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;
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re:x2 noshow by file extension
by grinder (Bishop) on Jun 03, 2002 at 13:47 UTC | |
by Aristotle (Chancellor) on Jun 03, 2002 at 21:47 UTC |