Hi, I built a HoH as follows:
# build hash while() { ... $hshFoo{$key1}{$key2} = $strFileName; ... # key1 is a number # key2 is a sequential number }
The entries are placed in seqential order such as:
$hshFoo{2823}{0} = 2823_0.xml $hshFoo{2823}{1} = 2823_1.xml $hshFoo{2823}{2} = 2823_2.xml $hshFoo{2823}{3} = 2823_3.xml
When I dump the hash, the keys come out as follows:
foreach $key1 (keys %hshFoo) { foreach $key2 (keys %{$hshFoo{$key1}}) { print "$key1/$key2 => $hshFoo{$key1}{$key2}\n"; } } ... Output: 2823/1 => 2823_1.xml 2823/0 => 2823_0.xml 2823/3 => 2823_3.xml 2823/2 => 2823_2.xml ... I expected: 2823/0 => 2823_0.xml 2823/1 => 2823_1.xml 2823/2 => 2823_2.xml 2823/3 => 2823_3.xml
The files were originally placed in the hash from a sorted array. Are the keys not in order within the hash or does Perl just grab the keys in any order?
Just curious. :)

-P0w3rK!d


In reply to Hash key ordering question by P0w3rK!d

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.