Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Deterministic or keys in random order

by reasonablekeith (Deacon)
on May 14, 2008 at 14:39 UTC ( [id://686533]=note: print w/replies, xml ) Need Help??


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.

Replies are listed 'Best First'.
Re^2: Deterministic or keys in random order
by andreas1234567 (Vicar) on May 14, 2008 at 18:29 UTC
    As a Perl programmer you should never write code which relies on the order returned by keys/each.
    That's exactly why I think this particular exam question is flawed.
    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found