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

That's a completely different data structure now!!!

 @sorted = sort { $a->{Score} <=> $b->{Score} } @entry

Does it.

Cheers Rolf

(addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^4: Advance Sorting
by Anonymous Monk on Jun 03, 2014 at 17:03 UTC

    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
       
      @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)