>Ребята подскажите как правильн отсортировать хеш
>есть хеш %in
>foreach $key (sort keys %in) {.....}
>выводит ключи
>10.0.0.1
>10.0.0.10
>10.0.0.11
>10.0.0.2
>10.0.0.20
>10.0.0.21
====
В этом случае может помочь:
sub super_sort {
my ($field,$f_sep,$hash_name) = @_;
# @a = split($f_sep,${$hash_name}{$a}); # sort by value
# @b = split($f_sep,${$hash_name}{$b}); # sort by value
@a = split($f_sep,$a); # sort by key
@b = split($f_sep,$b); # sort by key
if ($a[$field] =~ /^\d+$/ && $b[$field] =~ /^\d+$/) {
$a[$field] <=> $b[$field];
} else {
uc($a[$field]) cmp uc($b[$field]);
}
}
$hash_name = 'in'; #need only for sort by value
$number_of_field = 3; # begin from 0;
$field_separator = '\.';
foreach $x (sort {super_sort ($number_of_field,$field_separator,$hash_name) } (keys %in)) {
print "$x ($in{$x})\n";
}