Syntactic Confectionery Delight | |
PerlMonks |
Complex sort of array of hashes into an array of arraysby BioJL (Initiate) |
on Nov 23, 2010 at 15:08 UTC ( [id://873227]=perlquestion: print w/replies, xml ) | Need Help?? |
BioJL has asked for the wisdom of the Perl Monks concerning the following question: Hi, I'm a newbie in perl (also in programming), so I'll try to explain myself... I have an array of hashes with the following structure $matrix[0]{A} = 22... $matrix[1]{C} = 30... ... [A->22, C->51, G->7, T->0] [A->9, C->30, G->0, T->2] [and so on ] I want to sort each row in another array of arrays by the values of each hash, but keeping the information of the letter. For instance: @sorted[][] [ 51 22 7 0 C A G T ] [ 30 9 2 0 C A T G ] ... So i can relate 51 with C, 22 with C, etc. Thanks in advance! I tried to do the thing that kennethk proposes but i got lost in the syntax because It's a hash into an array. @sorted = sort { {$a} <=> {$b} } keys @matrix[$pos]{};
Back to
Seekers of Perl Wisdom
|
|