Try using a hash of arrays or hash of hashes. Without more info it's not clear which is better for your application. This way you can sort the hash by keys or by a particular value, or whatever. if array_a is names, array_b is birth_order and array_c is salary (just for example) you could replace those arrays with a structure like this:
# First make a hash to hold it all my %p = (); # p is short for people so I can type less. # bob, fred, peter and john are keys of %p, and refs to # hashes we didn't predeclare. This is what makes hashes # of hashes (or arrays) so useful, they are easily # populated from unknown data. $p{bob}{birth_order} = 1; $p{fred}{birth_order} = 2; $p{peter}{birth_order} = 3; $p{john}{birth_order} = 4; $p{bob}{salary} = 50000; $p{fred}{salary} = 60000; $p{peter}{salary} = 70000; $p{john}{salary} = 80000; # to sort by the people's names: for my $name ( sort keys %p ){ # do something here } # to sort by the people's birth order: for my $name ( sort { $p{$a}{birth_order} <=> $p{$b}{birth_order} } +keys %p ) { print "$p{$name}{birth_order}, $name\n"; }
I wrote out a bit of it long hand just to illustrate, but there are certainly better ways of creating these hashes.

In reply to Re: Sorting multiple arrays by keck
in thread Sorting multiple arrays by Kempie

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.