本文介绍了在Perl中排序数组数组的哈希散列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我打了一个哈希(%轨迹
)组织我的数据,当我打印它与 Data :: Dumper
它显示数据结构:
'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' ','1.95','0.976184'
]
]
},
如何使用数组 $ _ [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'
],
]
数据结构,但与内部数组组织。感谢提前。
解决方案
我只是试着猜测你在找什么,因为你不清楚你想要什么。 $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ @ $ inner = sort {$ a-> [17]< => $ b-> [17]} @ $ inner;
}
}
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.
解决方案
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;
}
}
这篇关于在Perl中排序数组数组的哈希散列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!