Ok, we're nearly there.. but I have one mysterious problem I cannot understand:

I inserted this code:
my @names_and_rates = map { [ $_->{name}[0], $_->{data}[0] ],[ $_- +>{name}[1], $_->{data}[1] ] } @alldata; @maxref = sort { $b->[1] <=> $a->[1] } @names_and_rates; foreach (@maxref[0 .. 2] ) { print $_->[0], "\t\t", $_->[1]*8, "\n +<BR>"; }
But got this:
file      rate
          384434.306056 
          191966.35544 
          122524.077608 
So clearly I'm missing the {name} parameter. So, I figured what I needed to do was flatten out the @alldata array a bit. I used this:
Update Fixed a minor typo in the code below...
my @maxtmp = sort { $b->{data} <=> $a->{data} } @alldata; my @names_and_rates = map { [ $_->{name}, $_->{data}->[0] ],[ $_-> +{name}, $_->{data}->[1] ] } @maxtmp; @maxref = sort { $b->[1] <=> $a->[1] } @names_and_rates; foreach (@maxref[0 .. 2] ) { print $_->[0], "\t\t", $_->[1]*8, "\n +<BR>"; }
..And it worked!
Now I just need to know a more effective way than that first sort to flatten out the array, since the first sort operation (to @maxtmp) is wasted - but I didn't know how to use the map command to do the same thing.

Any hints?!? Update 2: Thanks to arturo for the simple fix, below:
my @names_and_rates = map { [ $_->{name}, $_->{data}->[0] ],[ $_-> +{name}, $_->{data}->[1] ] } @alldata; @maxref = sort { $b->[1] <=> $a->[1] } @names_and_rates; #this next bit just prints the top three foreach (@maxref[0 .. 2] ) { print $_->[0], "\t\t", $_->[1]*8, "\n +<BR>"; }

Signature void where prohibited by law.

In reply to Ooooo so Close... by Clownburner
in thread Help with multidimensional sorting on arrays of hashed arrays by Clownburner

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.