
gevni
Novice
Nov 29, 2012, 4:54 PM
Post #9 of 10
(5876 views)
|
Re: [Laurent_R] How to sort multidimensional array?
[In reply to]
|
Can't Post
|
|
Thank you all for your help. @Laurent_R yes you are right. I change it into array and get sorted result. Thanks. I am posting me changed corrected code here so if any one has the same problem, he will get idea.
sub sort_1 { my $ref_partition = shift; my @array = (); my $i; my $j; my @test; for($j=0;$j <= $#$ref_partition; $j++){ my $col_1= $ref_partition->[$j]; my @col = sort { $a->[7] <=> $b->[7]} @{$col_1}; my $height=0; for($i=0;$i <= $#col; $i++){ my @test = @{$col[$i]}; $array[$i] = [$test[0],$height,@test[2..$#test]]; $height += $col[$i][3]; } $ref_partition->[$j] = \@array; print Dumper $ref_partition->[$j]; } } My Damper print value is $VAR1 = [ [ 'edel-55.0', 0, '534', '807', '430938', '40401MB', '7506207.000000', 0 ], [ 'edel-62.5', 807, '534', '673', '359382', '33692MB', '7501276.000000', 2 ], [ 'edel-62.0', 1480, '534', '568', '303312', '28436MB', '7487031.000000', 2 ] ]; $VAR1 = [ [ 'edel-55.1', 0, '579', '519', '300501', '28172MB', '7505535.000000', 0 ], [ 'edel-62.3', 519, '579', '523', '302817', '28389MB', '7500000.000000', 2 ], [ 'edel-62.1', 1042, '579', '523', '302817', '28389MB', '7500312.000000', 2 ] ]; $VAR1 = [ [ 'edel-59.1', 0, '477', '541', '258057', '24193MB', '7510249.000000', 1 ], [ 'edel-59.0', 541, '477', '478', '228006', '21376MB', '7497292.000000', 1 ], [ 'edel-62.4', 1019, '477', '552', '263304', '24685MB', '7485529.000000', 2 ] ]; As here i use $ref_partition->[$j] = \@array; So it will overwrite last $j value into array. How i can store all values of &j ? some thing like: get sorted value for each &j store them into array and pass the referece of that array which has all sorted value of $j into $ref_partition= \@array; Thank again!!
|