in reply to Sort array using a ranking system from separate hash

Assuming you have your "number of arrays" stored as an array of arrays:

#! perl -slw use strict; use Data::Dump qw[ pp ]; my @AoAs = ( [ qw[ TTVVRRRDR KFRQLLWFH RSQSPRRRR CSPHHTALR WIRTPPAYR VVRRRDRGR +HISCLTFGR RTPSPRRRR NTNMGLKFR LVSFGVWIR ] ], [ qw[ AILCWGELM TVLEYLVSF GLKFRQLLW LSFLPSDFF LLSFLPSDF LLWFHISCL +MQLFHLCLI QLFHLCLII ATVELLSFL ALRQAILCW ] ], [ qw[ TTVVRRRDR CSPHHTALR WIRTPPAYR NVNMGLKIR LVSFGVWIR HISCLTFGR +] ], [ qw[ CSPHHTALR YVNTNMGLK WIRTPPAYR TLPETTVVR HISCLTFGR NTNMGLKIR +WGMDIDPYK LVSFGVWIR ] ], ); my %freq; map ++$freq{ $_ }, @$_ for @AoAs; @$_ = sort{ $freq{ $b } <=> $freq{ $a } } @$_ for @AoAs; pp \@AoAs __END__ C:\test>1169316 [ ["CSPHHTALR", "WIRTPPAYR", "HISCLTFGR", "LVSFGVWIR", "TTVVRRRDR", "K +FRQLLWFH", "RSQSPRRRR", "VVRRRDRGR", "RTPSPRRRR", "NTNMGLKFR"], ["AILCWGELM", "TVLEYLVSF", "GLKFRQLLW", "LSFLPSDFF", "LLSFLPSDF", "L +LWFHISCL", "MQLFHLCLI", "QLFHLCLII", "ATVELLSFL", "ALRQAILCW"], ["CSPHHTALR", "WIRTPPAYR", "LVSFGVWIR", "HISCLTFGR", "TTVVRRRDR", "N +VNMGLKIR"], ["CSPHHTALR", "WIRTPPAYR", "HISCLTFGR", "LVSFGVWIR", "YVNTNMGLK", "T +LPETTVVR", "NTNMGLKIR", "WGMDIDPYK"], ]

Update: you might want to include a tie-break for those with an equal frequency to ensure consistency. Eg. Here I've used increasing aplha ordering as the tie break which makes the output more consistent:

#! perl -slw use strict; use Data::Dump qw[ pp ]; $Data::Dump::WIDTH = 200; my @AoAs = ( [ qw[ TTVVRRRDR KFRQLLWFH RSQSPRRRR CSPHHTALR WIRTPPAYR VVRRRDRGR +HISCLTFGR RTPSPRRRR NTNMGLKFR LVSFGVWIR ] ], [ qw[ AILCWGELM TVLEYLVSF GLKFRQLLW LSFLPSDFF LLSFLPSDF LLWFHISCL +MQLFHLCLI QLFHLCLII ATVELLSFL ALRQAILCW ] ], [ qw[ TTVVRRRDR CSPHHTALR WIRTPPAYR NVNMGLKIR LVSFGVWIR HISCLTFGR +] ], [ qw[ CSPHHTALR YVNTNMGLK WIRTPPAYR TLPETTVVR HISCLTFGR NTNMGLKIR +WGMDIDPYK LVSFGVWIR ] ], ); my %freq; map ++$freq{ $_ }, @$_ for @AoAs; @$_ = sort{ $freq{ $b } <=> $freq{ $a } || $a cmp $b } @$_ for @AoAs; pp \@AoAs __END__ C:\test>1169316 [ ["CSPHHTALR", "HISCLTFGR", "LVSFGVWIR", "WIRTPPAYR", "TTVVRRRDR", "K +FRQLLWFH", "NTNMGLKFR", "RSQSPRRRR", "RTPSPRRRR", "VVRRRDRGR"], ["AILCWGELM", "ALRQAILCW", "ATVELLSFL", "GLKFRQLLW", "LLSFLPSDF", "L +LWFHISCL", "LSFLPSDFF", "MQLFHLCLI", "QLFHLCLII", "TVLEYLVSF"], ["CSPHHTALR", "HISCLTFGR", "LVSFGVWIR", "WIRTPPAYR", "TTVVRRRDR", "N +VNMGLKIR"], ["CSPHHTALR", "HISCLTFGR", "LVSFGVWIR", "WIRTPPAYR", "NTNMGLKIR", "T +LPETTVVR", "WGMDIDPYK", "YVNTNMGLK"], ]

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Sort array using a ranking system from separate hash
by Sandy_Bio_Perl (Beadle) on Aug 08, 2016 at 10:41 UTC

    Thank you BrowserUK. I suspect I have rather poorly explained my problem. I have tried to clarify with my response to Rolf elsewhere in this node

      I'm pretty sure that my code will do what you want -- order a small array by the ordering contained in a hash.

      My misunderstanding was that I thought you meant you had many arrays in a single run, rather than one array per run.

      However, the basic process of sorting an array according to a frequency hash remains the same:

      my %freq = ...; my @array = qw[ data items here ]; my @ordered = sort{ $freq{ $b } <=> $freq{ $a } } @array; ## for highe +st frequency first.

      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Thanks, works brilliantly

        Thank you

Re^2: Sort array using a ranking system from separate hash
by Sandy_Bio_Perl (Beadle) on Aug 08, 2016 at 12:15 UTC

    Thanks for the tie-break, that works really well. Much appreciated