in reply to Advance Sorting

> I presume once it's sorted and I don't add anything it will stay sorted?

Nope. Hashes can't be sorted, only their keys can be sorted and held in a separate array.

Otherwise please elaborate better what you want to achieve your post is rather cryptic...

Cheers Rolf

(addicted to the Perl Programming Language)

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

    I see thanks for that. I have a list of IDs with a corresponding score and location values. I want to order the IDs based on highest score associated with them. I also want the IDs to be grouped together. When I use array of hashes like below how would I order it then?

    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', }; Output; TRA 15 7-15 BLA 10 2-10 BLA 5, 1-10
      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)

        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