Leser: 1
10 Einträge, 1 Seite |
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
#!/usr/bin/perl -w
use strict;
my @argA = ('hallo', 3, 'Hallo', "", 22, "das war's" );
print "Unsortiert\n";
for (0..5) {
if(defined $argA[$_]) {
print "$_=$argA[$_] <\n";
}
else {
print "$_ ist undefiniert\n";
}
}
@argA = sort @argA;
print "\nSortiert, lexikalisch\n";
for (0..5) {
if(defined $argA[$_]) {
print "$_=$argA[$_] <\n";
}
else {
print "$_ ist undefiniert\n";
}
}
@argA = sort {$a <=> $b} @argA;
print "\nSortiert, numerisch aufsteigend\n";
for (0..5) {
if(defined $argA[$_]) {
print "$_=$argA[$_] <\n";
}
else {
print "$_ ist undefiniert\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
Unsortiert
0=hallo <
1=3 <
2=Hallo <
3= <
4=22 <
5=das war's <
Sortiert, lexikalisch
0= <
1=22 <
2=3 <
3=Hallo <
4=das war's <
5=hallo <
Argument "" isn't numeric in ncmp at yy.pl line 27.
Argument "Hallo" isn't numeric in ncmp at yy.pl line 27.
Argument "das war's" isn't numeric in ncmp at yy.pl line 27.
Argument "hallo" isn't numeric in ncmp at yy.pl line 27.
Sortiert, numerisch aufsteigend
0= <
1=Hallo <
2=das war's <
3=hallo <
4=3 <
5=22 <
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use Scalar::Util qw[ looks_like_number ];
sub special_compare {
my ($x, $y) = @_;
if(&looks_like_number($x) and &looks_like_number($y)) {
return ($x <=> $y);
} else {
return (lc $x cmp lc $y);
}
}
my @argA = ('hallo', 3, 'Hallo', "", 22, "das war's" );
@argA = sort { special_compare($a, $b) } @argA;
print join("\n", @argA);
1
2
3
4
5
6
7
sub special_compare {
return $a <=> $b
if looks_like_number($a) and &looks_like_number($b);
return lc $a cmp lc $b;
}
@argA = sort special_compare @argA;
return ($irgendwas)
if (my @items = &DoWhatEver()) {
return $irgendwas;
if { $irgendwas } {
return ($irgendwas)
if (my @items = &DoWhatEver()) {
return $irgendwas;
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
#!/usr/bin/perl
use strict;
use warnings;
sub foo1 { return undef; }
sub foo2 { return (undef); }
sub foo3 { return(undef); }
sub foo4 { my @myarr; return @myarr; }
sub foo5 { my @myarr; return (@myarr); }
sub foo6 { my @myarr; return(@myarr); }
sub foo7 { return 1; }
sub foo8 { return (1); }
sub foo9 { return(1); }
use Data::Dumper;
my @arr1 = foo1();
my @arr2 = foo2();
my @arr3 = foo3();
my @arr4 = foo4();
my @arr5 = foo5();
my @arr6 = foo6();
my @arr7 = foo7();
my @arr8 = foo8();
my @arr9 = foo9();
print Dumper \@arr1;
print Dumper \@arr2;
print Dumper \@arr3;
print Dumper \@arr4;
print Dumper \@arr5;
print Dumper \@arr6;
print Dumper \@arr7;
print Dumper \@arr8;
print Dumper \@arr9;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$VAR1 = [
undef
];
$VAR1 = [
undef
];
$VAR1 = [
undef
];
$VAR1 = [];
$VAR1 = [];
$VAR1 = [];
$VAR1 = [
1
];
$VAR1 = [
1
];
$VAR1 = [
1
];
return ($irgendwas)
10 Einträge, 1 Seite |