Perl是否保证返回一致的散列键? [英] Is Perl guaranteed to return consistently-ordered hash keys?

查看:137
本文介绍了Perl是否保证返回一致的散列键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出类似于

Given something like

foreach (keys %myHash) {
   ... do stuff ...
}

foreach (keys %myHash) {
   ... do more stuff ...
}

如果散列值没有改变,Perl是否保证以一致的顺序迭代键值?

Is Perl guaranteed to iterate over the keys in a consistent order if the hash is not altered?

推荐答案

。从 perldoc -f键

Yes. From perldoc -f keys:


这些键以明显随机的顺序返回。实际的随机顺序在未来版本的perl中可能会发生变化,但保证与顺序相同。每个函数都会产生(假设散列没有被修改)。自Perl 5.8.1以来,出于安全原因,即使在不同的Perl运行之间,排序也是不同的(请参阅 perldoc perlsec )。

The keys 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 the same order as either the values or each function produces (given that the hash has not been modified). Since Perl 5.8.1 the ordering is different even between different runs of Perl for security reasons (see "Algorithmic Complexity Attacks" in perldoc perlsec).

(强调我的)

这篇关于Perl是否保证返回一致的散列键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆