in reply to Sorting Complex Data Structure

Creating a hash is a good way. You can sort the result for each id, so you do not have to search for the same ids.
my %by_id; push @{ $by_id{ $_->{id} } }, $_->{score} for @data; # Sort the scores for each id. $_ = [ sort { $b <=> $a } @$_ ] for values %by_id; # Sort the ids by the highest score. for my $id (sort { $by_id{$b}[0] <=> $by_id{$a}[0] } keys %by_id) { print "ID: $id\tScore: $_\n" for @{ $by_id{$id} }; }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Sorting Complex Data Structure
by Anonymous Monk on Jan 21, 2014 at 14:30 UTC

    Hi choroba,

    Thanks that seemed to do the trick. The remaining issue is that I have a lot of other features saved in the original data structure (that varies depending on task). Is there a way to perhaps link this with the original array indexes, save the order and then print it using this order? Thanks again