Until today, I thought that hash keys were randomised when returned. However, the entry in perldoc on keys suggests otherwise:
Hash entries are returned in an apparently random order. The actual random order is specific to a given hash; the exact same series of operations on two hashes may result in a different order for each hash.
There are other entries on SO that relate to this - most pertinent is the accepted answer to this question.
The following code returns apparently randomised hash keys:
my %hash;
$hash{$_}++ for 1 .. 100;
say for keys %hash;
Can anyone help me understand how this is not actually random?
Aucun commentaire:
Enregistrer un commentaire