Leser: 1
|< 1 2 >| | 20 Einträge, 2 Seiten |
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
use strict;
my $arrayVar;
$arrayVar->{"0,0"} = "a";
$arrayVar->{"1,0"} = "a";
$arrayVar->{"2,0"} = "a";
$arrayVar->{"3,0"} = "a";
$arrayVar->{"4,0"} = "b";
$arrayVar->{"0,1"} = "2";
$arrayVar->{"1,1"} = "2";
$arrayVar->{"2,1"} = "3";
$arrayVar->{"3,1"} = "3";
$arrayVar->{"4,1"} = "3";
$arrayVar->{"0,2"} = "aaa";
$arrayVar->{"1,2"} = "bbb";
$arrayVar->{"2,2"} = "aaa";
$arrayVar->{"3,2"} = "bbb";
$arrayVar->{"4,2"} = "bbb";
$arrayVar->{"0,3"} = "1";
$arrayVar->{"1,3"} = "2";
$arrayVar->{"2,3"} = "3";
$arrayVar->{"3,3"} = "4";
$arrayVar->{"4,3"} = "5";
my @data;
# $arrayVar umwandeln in 2-dim. Array:
for (keys %$arrayVar) {
my ($y, $x) = split /,/;
$data[$y][$x] = $arrayVar->{$_};
}
# Array sortieren nach $spalte:
my $spalte = 0; # erste Spalte
my @sorteddata = sort { $a->[$spalte] cmp $b->[$spalte] } @data;
# $arrayVar neu aufbauen mit @sorteddata:
$arrayVar = {};
for my $y (0 .. $#sorteddata) {
for my $x (0 .. $#{$sorteddata[$y]}) {
$arrayVar->{"$y,$x"} = $sorteddata[$y][$x];
}
}
# testen:
use Data::Dumper;
print Dumper \@sorteddata;
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
use strict;
my $arrayVar;
$arrayVar->{"0,0"} = "a";
$arrayVar->{"1,0"} = "a";
$arrayVar->{"2,0"} = "a";
$arrayVar->{"3,0"} = "a";
$arrayVar->{"4,0"} = "a";
$arrayVar->{"0,1"} = "3";
$arrayVar->{"1,1"} = "2";
$arrayVar->{"2,1"} = "2";
$arrayVar->{"3,1"} = "3";
$arrayVar->{"4,1"} = "3";
$arrayVar->{"0,2"} = "aaa";
$arrayVar->{"1,2"} = "bbb";
$arrayVar->{"2,2"} = "aaa";
$arrayVar->{"3,2"} = "bbb";
$arrayVar->{"4,2"} = "bbb";
my @data;
# $arrayVar umwandeln in 2-dim. Array:
for (keys %$arrayVar) {
my ($y, $x) = split /,/;
$data[$y][$x] = $arrayVar->{$_};
}
# Array sortieren nach $spalte:
my @sorteddata = sort { $a->[0] cmp $b->[0] || $a->[1] <=> $b->[1] ||$a->[2] cmp $b->[2] } @data;
# $arrayVar neu aufbauen mit @sorteddata:
$arrayVar = {};
for my $y (0 .. $#sorteddata) {
for my $x (0 .. $#{$sorteddata[$y]}) {
$arrayVar->{"$y,$x"} = $sorteddata[$y][$x];
}
}
# testen:
use Data::Dumper;
print Dumper \@sorteddata;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
my @sorteddata = sort rulez1 @data;
...
sub rulez1
{
my $test;
if ( $a->[0] =~ /^[0-9]*$/ && $b->[0] =~ /^[0-9]*$/ )
{
$test = $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1];
}
else
{
$test = $a->[0] cmp $b->[0] || $a->[1] cmp $b->[1];
}
return $test;
}
|< 1 2 >| | 20 Einträge, 2 Seiten |