Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: What makes an array sorted and a hash unsorted?

by shmem (Chancellor)
on Jun 01, 2009 at 17:36 UTC ( [id://767334]=note: print w/replies, xml ) Need Help??


in reply to Re^2: What makes an array sorted and a hash unsorted?
in thread What makes an array sorted and a hash unsorted?

... even after the 5.8.1 change to add randomisation.

So, while not yet perfect, the tendency is to randomize the order in which keys or values are returned. keys and values are meant to return their values in no predictable order.

You say,

keys may not return the keys in order, but it could.

Yes, e.g. tying the hash to DB_File, as DB_BTREE. But what's your point? In theory, it could, but in practice, it doesn't. In which theoretical circumstances that would be meaningful in practice, would keys return the keys of a perl untied hash in any meaningful order (i.e. shortest..longest, lexically sorted, lifo/fifo or such) ? And why should it?

Replies are listed 'Best First'.
Re^4: What makes an array sorted and a hash unsorted?
by ikegami (Patriarch) on Jun 01, 2009 at 17:44 UTC

    But what's your point? In theory, it could, but in practice, it doesn't.

    My answer to Roy answers this as well.

    keys and values are meant to return their values in no predictable order.

    No, it's not a feature, it's a side-effect. It would be needlessly costly to return them sorted. Why is it needless? Because people would still want custom sorting of the keys. (With arrays, they want custom sorting of the values.)

Log In?
Username:
Password:

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

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

    No recent polls found