Thread Array sortieren das Strings und Interger enthaelt (9 answers)
Opened by roli at 2006-04-05 18:20

esskar
 2006-04-05 18:46
#64383 #64383
User since
2003-08-04
7321 Artikel
ModeratorIn

user image
Code: (dl )
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);

View full thread Array sortieren das Strings und Interger enthaelt