Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by DStaal (Chaplain)
on Jun 01, 2009 at 17:15 UTC ( [id://767328]=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?

The point isn't that there is a way to sort them. It's whether you need to use it to guarantee the order you get: With an array you don't, with a hash you do.

And yes, may. But the point is on the array the order will not. You can be sure of that: That given the same input, you will get the same output. A hash intentionally does not guarantee that.

And no, sorting the keys does not make the hash sorted. It simply means you have a sorted array that can be used to access the hash in a sorted order.

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

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:25 UTC

    The point isn't that there is a way to sort them.

    Of course you can. Just like array indexes are ordered in ascending numeric order, hash keys can be ordered in ascending lexical order.

    You don't see people telling arrays that 5 sorts after 4. No, they change the key-value associations instead. You can do exactly the same thing with hashes. The difference is that people don't want to change the key-value associations for hashes.

    Thus my conclusion: That hashes are unsorted isn't a property of hashes so much as of the way we use them.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-18 12:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found