http://qs1969.pair.com?node_id=686533


in reply to Deterministic or keys in random order

Just to be explict. You do realise that the fact Zero is returned as the first key has nothing to do with the order of insertion?

All of these print "Zero" on my build of perl (5.8.7)

my %hash = ( "Zero" =>"0", "One" => "1", "Two" => "2", ); my @array = keys %hash; print $array[0] . "\n"; -------------------------- my %hash = ( "One" => "1", "Zero" =>"0", "Two" => "2", ); my @array = keys %hash; print $array[0] . "\n"; -------------------------- my %hash = ( "Two" => "2", "One" => "1", "Zero" =>"0", ); my @array = keys %hash; print $array[0] . "\n";
As a Perl programmer you should never write code which relies on the order returned by keys/each (apart from it being the same as the list time you checked, if you’ve not updated the array).
---
my name's not Keith, and I'm not reasonable.