Generally, you can do this with multi-level sorts. A naive implementation might look like this:
# load data into a list of hash-refs my @data = ( { Subject => 'ID12', Query => 'KBrH', start => 22400316, ... }, ... ); my @sorted = sort { $a->{Subject} cmp $b->{Subject} or $a->{start} <=> $b->{start} } @data;
I've written a CPAN module to make this kind of thing trivial: Data::Sorting.

If you've loaded your data into a list of hash-refs:

use Data::Sorting 'sort_array'; sort_array( @data, 'Subject', 'start' );

Alternately, if you've loaded your data into an array of arrays like this:

my $data = [ [ 'ID12', 'KBrH', '2e-26', 22400316, ... ], ... ]; use Data::Sorting 'sort_arrayref'; sort_arrayref( $data, 0, 3 );

There are other functions that return a sorted copy of the array, if you don't want to change the order of the original.

use Data::Sorting 'sorted_array'; my @sorted = sorted_array( @data, 'Subject', 'start' );

It'll run slower than a well-written inline sort statement, but it does some tricks under the covers to keep the performance up to acceptable levels (automatically picking a Schwartizian Transform or Guttman-Rossler strategy based on the arguments received), and you only need to write one line of code rather than a confusing block expression.


In reply to Re: Sorting complex records by simonm
in thread Sorting complex records by Anonymous Monk

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.