Ok, so, when you do:
foreach my $symbol_set (sort keys %pnl_ind) {
it returns you a sort set of keys from the top level of the hash...
my $symbols_r=$pnl_ind{$symbol_set);
stores the reference to the second level hash element under the current $symbol_set (which is now in sorted order)
foreach my $symbol (sort ($symbols_r->{$a}{'pnl'}<=>$symbols_r->{$b}{' +pnl'}) keys %{$symbols_r} ) {
the keys %{$symbols_r} derefences the hash ref, so that you can go through the keys... he wants to sort through the symbol patrt of the hash by the value associated with the pnl key inside the symbol part of the hash. No, since the sort is looking at the keys of the symbol level of the hash, $a and $b hold keys, so you do $symbols_r->{$a}{'pnl'} to get the value of the pnl key and <=> it to the $symbols_r->{$b}{'pnl'}. Normally sort would compare $a and $b directly, but since you want the values inside the hash, you need to get the values out using $a and $b as keys, to get to the real sort data... so now the hash comes back sorted by symbol_set, and within symbol set you get symbols ordered by their pnl values (whatever a pnl value is)

make more sense?
                - Ant


In reply to Re: Re: sorting hash of hashes by suaveant
in thread sorting hash of hashes by tevads

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.