本帖最后由 jason680 于 2014-08-27 14:56 编辑
@afukada @jiuling
>>那为什么每次运行的结果都是一样的顺序呢?
on Linux(ubuntu 12.04)
$ perl -le '$h{$_}=1 for(0..6); print join",",keys %h'
6,4,1,3,0,2,5
$ perl -le '$h{$_}=1 for(0..6); print join",",keys %h'
6,4,1,3,0,2,5
$ perl -le '$h{$_}=1 for(0..5); print join",",keys %h'
4,1,3,0,2,5
$ perl -le '$h{$_}=1 for(0..7); print join",",keys %h'
6,3,7,2,1,4,0,5
固定的内容(keys)有时会是固定的结果(相同的OS,相同的perl版本)....
但只要一增加或减少key,就结果完全不一样....
对User(programmer)而言,就是无序....
(而且Perl的解释器也没保证,固定的键,就会有相同结果....)
on windows
C:\bat>perl -le "$h{$_}=1 for(0..7); print join',',keys %h"
6,4,7,0,2,5,3,1
C:\bat>perl -le "$h{$_}=1 for(0..7); print join',',keys %h"
2,4,1,6,3,5,7,0
C:\bat>perl -le "$h{$_}=1 for(0..6); print join',',keys %h"
6,1,3,2,4,5,0
C:\bat>perl -le "$h{$_}=1 for(0..6); print join',',keys %h"
0,6,5,2,3,4,1
|