给出类似的东西
foreach (keys %myHash) { ... do stuff ... } foreach (keys %myHash) { ... do more stuff ... }
如果哈希不被改变,Perl是否保证以一致的顺序迭代密钥?
解决方法
Yes.从
perldoc -f keys
开始:
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
oreach
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 07002).
(强调我的)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。