Sherlock has asked for the wisdom of the Perl Monks concerning the following question:
This seems to work except for the directories "." and "..", which I would like to appear at the very top of the directory listing (hence, be placed at the beginning of the array). Since I'm just checking for the presence of a "." to determine if the entry is a subdirectory or a file, the directories "." and ".." are considered files as well.sub SortDirectory() { my $arrayRef = $_[0]; my @fileArray; my $currIndex = 0; my $i; for ( $i = 0; $i < @$arrayRef; $i++ ) { if ( (grep /\./, $$arrayRef[$i]) != "" ) { $fileArray[$currIndex++] = splice(@$arrayRef,$i--,1); } } push (@$arrayRef, @fileArray); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using grep with wildcards
by chipmunk (Parson) on Apr 21, 2001 at 00:26 UTC | |
|
Re: Using grep with wildcards
by the_slycer (Chaplain) on Apr 21, 2001 at 00:17 UTC | |
by Sherlock (Deacon) on Apr 21, 2001 at 00:20 UTC | |
|
Re: Using grep with wildcards
by buckaduck (Chaplain) on Apr 21, 2001 at 01:17 UTC | |
|
Re: Using grep with wildcards
by Chady (Priest) on Apr 21, 2001 at 00:23 UTC |