
30.07.2007, 16:02
|
|
Постоянный
Регистрация: 06.06.2006
Сообщений: 515
Провел на форуме: 1985206
Репутация:
963
|
|
Сообщение от vladest
Скажите, как сделать так, что бы при обходе хэша в цикле его элементы выводились в нужном порядке.
Пример:
%hash =('1'=>'1',
'2'=>'2',
'3'=>'3');
while ( ($k, $v) = each(%hash) ){
print "$k = $v \n";
}
выводит:
1 = 1
3 = 3
2 = 2
Почему? надо что бы 1,2,3
perldoc -f each
Код:
Entries are returned in an apparently random order. The actual
random order is subject to change in future versions of perl,
but it is guaranteed to be in the same order as either the
"keys" or "values" function would produce on the same
(unmodified) hash. Since Perl 5.8.1 the ordering is different
even between different runs of Perl for security reasons (see
"Algorithmic Complexity Attacks" in perlsec).
Через each ты не получишь в порядке объявления
|
|
|