in reply to Re^3: Advance Sorting
in thread Advance Sorting

If hashes cannot be order I have to change the data structure. My previous example was however quite bad - it's not a simple ordering by Score. I want to order by top Score per ID (BLA, TRA) and then order by score for particular IDs score, grouping them together. Below is a bit better example. Apologies for confusing you and thanks for help;

my @entry; push @entry, { ID => 'BLA', Score => 5, Location => '1-10', }; push @entry, { ID => 'TRA', Score => 15, Location => '7-15', }; push @entry, { ID => 'BLA', Score => 10, Location => '2-10', }; push @entry, { ID => 'BLA', Score => 35, Location => '90-150', }; Output; BLA 35 90-150 BLA 10 2-10 BLA 5, 1-10 TRA 15 7-15

Replies are listed 'Best First'.
Re^5: Advance Sorting
by LanX (Saint) on Jun 03, 2014 at 17:09 UTC
     
    @sorted = sort { $a->{ID} cmp $b->{ID} # alphanum asc or $b->{Score} <=> $a->{Score} # num. + desc } @entry

    See sort !

    Cheers Rolf

    (addicted to the Perl Programming Language)