Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: Hash order randomization is coming, are you ready?

by mje (Curate)
on Nov 29, 2012 at 17:11 UTC ( #1006308=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Hash order randomization is coming, are you ready?
in thread Hash order randomization is coming, are you ready?

A casual test looks like that statement is still true:

use 5.17.6; use strict; use warnings; my %a = ( z => 1, y => 2, x => 3); foreach (1..3) { print join(",", keys %a), "\n"; print join(",", values %a), "\n"; while (my ($d,$e) = each %a) { print "$d = $e\n"; } }

run 1

z,y,x 1,2,3 z = 1 y = 2 x = 3 z,y,x 1,2,3 z = 1 y = 2 x = 3 z,y,x 1,2,3 z = 1 y = 2 x = 3

run 2

x,y,z 3,2,1 x = 3 y = 2 z = 1 x,y,z 3,2,1 x = 3 y = 2 z = 1 x,y,z 3,2,1 x = 3 y = 2 z = 1


Comment on Re^3: Hash order randomization is coming, are you ready?
Select or Download Code
Re^4: Hash order randomization is coming, are you ready?
by demerphq (Chancellor) on Dec 02, 2012 at 10:03 UTC

    Yes indeed. This cannot change. And is guaranteed by the nature of the how keys() and values() are implemented in native hashes (non-magical). Basically they are both achieved by walking the bucket array from left to right and within a bucket from top to bottom. Since they both do the same data structure walk they both return the same results. However note this is true only of a /given/ hash. You can't assume that one hashes keys() will match another's values() even if they contain the same list of keys().

    ---
    $world=~s/war/peace/g

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1006308]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (13)
As of 2015-07-06 12:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls