A hash could be defined as an ordered list of key/value pairs.

I'll amplify your objections to your own offered premise. Since inserting a new key into a hash can significantly change the "order" of the previously inserted keys, I disagree that a Perl hash can be reasonably characterized as "an ordered list of key/value pairs". Certainly, at any given moment, the key/value pairs in an ordinary Perl hash have a defined order. And that particular order is quite useless, incidental, out of our control, and even inconstant. An "ordered" data structure mustn't shuffle its contents simply because a new item is being inserted. It is impossible to store items in computer memory and not have those items in some "order". That doesn't make every data structure into an "ordered data structure".

Since it is possible for %one= %two to leave %one with its keys in a different order than %two's, a Perl hash isn't "an ordered list of key/value pairs". Copying a hash doesn't (always) copy the order because the order is only an incidental part of the data structure.

- tye        


In reply to Re^2: What makes an array sorted and a hash unsorted? (fleas) by tye
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.