Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: keys and values order on a hash

by choroba (Cardinal)
on Jul 11, 2011 at 16:18 UTC ( [id://913717]=note: print w/replies, xml ) Need Help??


in reply to keys and values order on a hash

See 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" or "each" 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 perlsec).

Replies are listed 'Best First'.
Re^2: keys and values order on a hash
by ikegami (Patriarch) on Jul 11, 2011 at 16:42 UTC

    given that the hash has not been modified

    Specifically, changing the hash by adding or removing a key is what voids the guarantee, and so does assigning to keys. Changing a value does not affect the order.

    Adding or removing a key and then undoing the action still counts as a change. That means you can get different orders from two hashes with identical keys.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (7)
As of 2024-04-19 15:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found