OK, for those onlookers: After extensive conversation in the chatterbox, Clownburner told me the following:

{name} and {data} arrays map 1:1 onto each other, and the first two elements of the {data} array correspond to input and output rates, while the first two elements of the {name} array correspond to filenames.

Clownburner wants a list of filenames sorted by greatest rates (input or output).

First, get the list of name-value pairs for the first two values of {data} from @alldata

my @names_and_rates = map { [ $_->{name}[0], $_->{data}[0] ], [ $_->{name}[1], $_->{data}[1] ] } @alldata;

Now what you've got is an array, each element of which is an anonymous array consisting of a name -> rate pair. i.e.:

@names_and_rates = ( [ name1, rate1], [name2, rate2], ... );

What you want to do is sort that array by the second element of each anonymous array, i.e.

my @final_list = sort { $b->[1] <=> $a->[1] } @names_and_rates; # $b first for descending order

I think that will get you what you want. You can, of course, combine the two statements into one, e.g.

my @final_list = sort { #sort stuff } map { #map stuff } @alldata;

but I think that might be confusing if you come back to this code later, especially given the farrago of syntax. YMMV, IANAProfessional, etc.

I hope this is right and that it helps.

a nicety : if you want to print out the top n, do this:

print "File\t\tRate\n"; foreach (@final_list[0 .. $n-1] ) { print $_->[0], "\t\t", $_->[1], "\n"; }

Philosophy can be made out of anything. Or less -- Jerry A. Fodor


In reply to Re: Re: Re: Help with multidimensional sorting on arrays of hashed arrays by arturo
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.