Your initial data structure appears not to be a hash (despite the initial % sigil), but a hash reference, so that looping on the keys will fail.

Is this data structure something that you built yourself, or do you get it from another program or a subroutine/module call that you have not shown?

If you're building it yourself, then change it to something like:

%update = ( '2'=>{ '25' => { 'i' => 5000000, 'o' => 5000000 }, '4' => { 'o' => 5000000, 'i' => 5000000 } } );
(Parens instead of curlies for the external delimiters.)

If you're getting that hash ref data structure from somewhere else (e.g. another program or another part of your program), then you probably need to change your foreach loops to use a hashref instead of a hash. For example, change the foreach my $i (keys %update) line to something that uses an hash ref rather than a hash, for example, assuming your data hashref is $update, something like:

foreach my $i (keys %$update) { #...

In reply to Re: sorting hash of hashes by Laurent_R
in thread sorting hash of hashes by dilip.renkila

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.