Thread Dateisortierung (39 answers)
Opened by IceRage at 2012-02-04 02:17

FIFO
 2012-02-05 07:39
#155875 #155875
User since
2005-06-01
469 articles
BenutzerIn

user image
Dann nimm pq's Code, der ist elegant. Allerdings muss im sort der ST beim string-Vergleich $a und $b vertauscht werden, sonst wird absteigend sortiert:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use warnings;
use strict;

my $dir = 'C:/MyFolder';
opendir(my $dh, $dir);

my @files = map {
    $_->[2]
} sort {
    $b->[0] <=> $a->[0] or $a->[1] cmp $b->[1]
} map {
    [-d "$dir/$_" || 0, lc $_, $_]
} readdir $dh;

print "$_\n" for @files;
Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it? -- Brian Kernighan: "The Elements of Programming Style"

View full thread Dateisortierung