1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/
/abc/
/abc/test/
/abc/test/z.php4
/abc/test/z.txt
/asdf/
/asdf/123/
/asdf/A/
/asdf/B/
/asdf/B/C/
/asdf/B/C/a.file
/home/
/home/test/
/home/test/asdf/
/home/test/asdf/jklo/
/home/test/asdf/jklo/rstuv2/
/home/test/asdf/jklo/rstuvw11/
/root/config
/root/tmp/
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# fetch directories
my @dirs = do{
local $/ = undef;
split /\n/, <DATA>;
};
# mischen
fisher_yates_shuffle( \@dirs );
# sortieren
@dirs = sort{ weight($a) <=> weight($b) } @dirs;
while( my $e = shift @dirs ){
print "$e\n";
}
# perlfaq4
sub fisher_yates_shuffle {
my $deck = shift; # $deck is a reference to an array
return unless @$deck; # must not be empty!
my $i = @$deck;
while (--$i) {
my $j = int rand ($i+1);
@$deck[$i,$j] = @$deck[$j,$i];
}
}
# bewerten
sub weight{
my $path = shift;
my @p = split /\//, $path;
my $score = 0;
for( my $i = 0; $i < scalar @p; $i++){
$score += ord($p[$i]) * 2 ** $i;
}
return $score;
}
__DATA__
/
/abc/
/abc/test/
/abc/test/z.php4
/abc/test/z.txt
/asdf/
/asdf/123/
/asdf/A/
/asdf/B/
/asdf/B/C/
/asdf/B/C/a.file
/home/
/home/test/
/home/test/asdf/
/home/test/asdf/jklo/
/home/test/asdf/jklo/rstuv2/
/home/test/asdf/jklo/rstuvw11/
/root/config
/root/tmp/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/perl use strict; use warnings; use Unicode::Collate; # hier require() zu benutzen oder die Struktur anders bauen bringt keinen Vorteil, hab ich gemessen my $alphasorter_modul = Unicode::Collate->new(); my $alphasorter_regex = qr{[^0-9 a-z!"§$%&/()=?\{\[\]\}\]><|_\-+*,.:;#'~\^]}ix; my $alphasorter = sub { return defined $_[0] && defined $_[1] ? $_[0] =~ $alphasorter_regex || $_[1] =~ $alphasorter_regex ? $alphasorter_modul->cmp($_[0],$_[1]) : lc $_[0] cmp lc $_[1] : 0 ; }; my @test = ('Nüsse','Nut','Straße','Strass','stricken','Album','nehmen'); print "Perl : ".join(" ",sort {$a cmp $b} @test)."\n\n"; print "Eigen: ".join(" ",sort {$alphasorter->($a,$b)} @test)."\n\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#!/usr/bin/perl use strict; use warnings; use List::Util qw(shuffle); use File::Basename; print $_->[1] . $_->[0] . $_->[2] for sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] || $a->[2] cmp $b->[2] } map { [ fileparse($_, qr/\.[^.]*/) ] } shuffle (<DATA>); __DATA__ / /abc/ /abc/tes.pl /abc/test_5 /abc/test_42 /abc/test_foo.txt /abc/test_foo-2.txt /abc/test_foo01.txt /abc/test_foo_1.txt /abc/test/ /abc/test/z.php4 /abc/test/z.txt /abc-test/abc /asdf/ /asdf/123/ /asdf/A/ /asdf/B/ /asdf/B/C/ /asdf/B/C/a.file /home/ /home/test/ /home/test/asdf/ /home/test/asdf/jklo/ /home/test/asdf/jklo/rstuv2/ /home/test/asdf/jklo/rstuvw11/ /root/config /root/tmp/