Sorting a Hash of Hashes of Array of Arrays in Per

2019-02-20 05:46发布

问题:

I made a hash (%locus) to organise my data, when I print it with Data::Dumper it shows the data structure:

'locus8 >9.2668516.276570.GABA3.1.54.6586237.218516.2718570 74280 74440 locus8' 
 => {    
 '3 70.75 0.995018 -1.89 -' => [          
   [                                                                           
    'window10',                                                'locus8',         
    '>9.2668516.2768570.GABA3.1.54.6586237.2718516.2718570', '74280',      
     '74400',                                                  '-',              
    '3',                                                      '120',        
    '55.87',                                                  '-17.41',         
    '-11.92',                                                 '-10.60',         
    '-1.32',                                                  '1.57',           
    '-1.58',                                                  '0.68',           
    '2.76',                                                   '0.995018'        
    ],                                                                          
    [                          
      'window11',                                                'locus8',   
      '>9.2668516.276570.GABA3.1.54.6586237.218516.2718570', '74320',          
      '74440', '-', '3', '120', '70.75', '-22.97', '-17.28', '-15.07', '-2.21', 

      '-1.89', '0.75', '1.95', '0.976184'                                       
    ]  
  ]                                                                             
  },

How Can I sort the internal arrays by the last element in the arrays $_[17]?

[                                                           
  [
    'window11',                                                'locus8',
    '>9.+.2668516.2768570.GABA3.1.54.6586237.2718516.2718570', '74320',
    '74440',                                                   '-',
    '3',                                                       '120',
    '70.75',                                                   '-22.97',
    '-17.28',                                                  '-15.07',
    '-2.21',                                                   '1.55',
    '-1.89',                                                   '0.75',
    '1.95',                                                    '0.976184'
  ],
  [
    'window10',                                                'locus8',
    '>9.+.2668516.2768570.GABA3.1.54.6586237.2718516.2718570', '74280',
    '74400',                                                   '-',
    '3',                                                       '120',
    '55.87',                                                   '-17.41',
    '-11.92',                                                  '-10.60',
    '-1.32',                                                   '1.57',
    '-1.58',                                                   '0.68',
    '2.76',                                                    '0.995018'
  ],
]

I want to maintain the data structure but, with the 'internal arrays' organised. Thanks in advance.

回答1:

I just try guess what you are looking for because you are not clear what you want.

for my $outher (values %hash) {
    for my $inner (values %$outher) {
        @$inner = sort {$a->[17] <=> $b->[17]} @$inner;
    }
}