Howdy!

You're moving the goalposts.

When you print $h{$_}, you are imposing an order by the sequence of values you assign to $_. The output sequence you are generating is not intrinsic to the hash, but extrinsic.

Your definition of %h is also flawed. You can construct a hash from a list in the manner you do, but there is no assurance that the list you get by saying (%h) will be the same as the list you used to construct the hash.

You don't get a random list when you call keys(). The ordering of the keys is unpredictable at that level. It is deterministic, in that calling keys() repeatedly will give the same list until you add or delete an element from the hash. Then it may come back with a reordered list. The hypothetical "what if perl had" or "what if perl didn't have" questions look like attempts to redefine the question to make it complicated again.

yours,
Michael

In reply to Re^6: What makes an array sorted and a hash unsorted? by herveus
in thread What makes an array sorted and a hash unsorted? by ikegami

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.