Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Hash key ordering?

by jmcnamara (Monsignor)
on May 02, 2002 at 11:38 UTC ( [id://163507]=note: print w/replies, xml ) Need Help??


in reply to Hash key ordering?


Hashes with the same keys won't necessarily return the keys in the same order, as shown below. However, as Juerd points out, the order shouldn't change for a given hash if the keys don't change, also shown below.

The only problem that I can see is that the order the keys are returned in might change in a future release. So, I wouldn't rely on that.

#!/usr/bin/perl -wl use strict; my %h1; my %h2; @h1{1..10} = undef; print join " ", keys %h1; @h1{5..10, 1..4} = undef; print join " ", keys %h1; @h2{5..10, 1..4} = undef; print join " ", keys %h2; __END__ Prints: 1 2 3 10 4 5 6 7 8 9 1 2 3 10 4 5 6 7 8 9 1 2 3 4 10 5 6 7 8 9

--
John.

Replies are listed 'Best First'.
Re: Re: Hash key ordering?
by demerphq (Chancellor) on May 02, 2002 at 12:42 UTC
    A second thought: There should be no anticipation of the same set of keys being produced on two seperate runs, or even in different hashes, but keys will return the same list for the same hash in the same runs every time.

    Yves / DeMerphq
    ---
    Writing a good benchmark isnt as easy as it might look.

Re: Re: Hash key ordering?
by dargosch (Scribe) on May 02, 2002 at 12:06 UTC
    Thank you all for all the help on that issue.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-03-29 15:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found