This approach is unreliable. On my machine the script:
use Data::Dumper; print Dumper({ 1007 => "Hello", 1195 => "World", }); print Dumper({ 1195 => "World", 1007 => "Hello", });
produces the output:
$VAR1 = { 1195 => 'World', 1007 => 'Hello' }; $VAR1 = { 1007 => 'Hello', 1195 => 'World' };
The issue is that Data::Dumper just returns keys in the order that keys gave it, which returns keys that are in the same bucket in the insertion order. With a 2 key hash your odds of hitting this are 1/8. But when the hashing algorithm works right, a fixed portion of the keys wind up in a bucket with a neighbour. Therefore for larger hashes you are virtually guaranteed that the set of keys alone does not determine what order they come back in.

If this explanation confuses, then Re (tilly) 4: Flip Flop III - Musical Buckets may help.


In reply to Re (tilly) 1: compare two hashes inefficiently. by tilly
in thread compare two hashes inefficiently. by deprecated

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.