http://qs321.pair.com?node_id=767340

Yes, they'd be considered sorted.

Even with that change, I think we'll still get EXACTLY the same questions we get today. People want custom ordering of keys when dealing with hashes (as opposed to custom ordering of values when dealing with arrays).

So if your claim is true, that means the answer we currently give ("hashes are unsorted") is wrong because the hashes being sorted wouldn't help at all.

I actually believe that hash are unsorted, and I believe the answer we are giving is right.

When people think they have a hash in a particular order, it isn't generally ASCIIbetical order, but the order they put the elements into it.

Exactly. It's how we use hashes that makes them unsorted. The keys are actually part of the value, and thus can't be used for ordering.

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

Replies are listed 'Best First'.
Re^5: What makes an array sorted and a hash unsorted?
by Roy Johnson (Monsignor) on Jun 01, 2009 at 18:07 UTC
"Hashes are not sorted the way you think they are sorted" would be correct today as well as with your change. However, it is also (theoretically) possible to implement hashes that retain an order unrelated to their keys. If that were implemented, it would "help", and so the problem is that hashes are unsorted -- in that way.

I still contend that it is the language that makes them unsorted. It is not merely how we use them. Order has to be imposed externally on the data. There is no intrinsic ordering.

Caution: Contents may have been coded under pressure.

So hashes aren't ordered because the following doesn't work?

```\$h{foo} = 'a';
\$h{bar} = 'b';
\$h{baz} = 'c';

is(join(' ', values(%h)), "a b c");

I guess arrays aren't ordered either, then.

```\$a[2] = 'a';
\$a[0] = 'b';
\$a[1] = 'c';

is("@a", "a b c");