I've written a CPAN module to make this kind of thing trivial: Data::Sorting.# 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;
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |