From perldoc -f keys section of the perlfunc manpage:
The actual random order is subject to change in future versions of perl, but it is guaranteed to be the same order as either the "values" or "each" function produces (given that the hash has not been modified).
So in short you cannot depend on the keys, values, or each functions to provide results in a pre-determined order. There are ways around this .. I believe (haven't actually used it personally) that Tie::Hash Tie::IxHash can (will?) preserve hash order for you. Also, you can always sort the results of keys/values calls. For example:
my %h = ( ... ); foreach my $k ( sort { lc $a cmp lc $b } keys %h ){ # get keys sorte +d by lowercase of key ... } foreach my $k ( sort { lc $h{$a} cmp lc $h{$b} } keys %h ){ $ get key +s sorted by lowercase of value ... }

In reply to Re: Determining hash order for sorting array by davidrw
in thread Determining hash order for sorting array by PenguinPwrdBox

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.