Perl sorting a 3d array -


i wand sort 3-dimension array in perl. elements of array in form:

$arr_3d[inda][indb][indc] , , each element indc=1 number

what need is, given value of inda, sort sub-arrays indexed/defined indb, decreasing order of value of $arr_3d[inda][indb][indc=1],.

e.g. 1x2x2 array if:

$arr_3d[1][1][1] = 1 $arr_3d[1][1][2] = 4 $arr_3d[1][2][1] = 2 $arr_3d[1][2][2] = 3 

then after sorting :

$arr_3d[1][1][1] = 2 $arr_3d[1][1][2] = 3 $arr_3d[1][2][1] = 1 $arr_3d[1][2][2] = 4 

so after sorting sub-arrays $arr_3d[1][1] , $arr_3d[1][2] swapped. sorry messed description.. ideas?

regards, giorgos

this related " schwartzian transform in perl? " . sorting single array (@{ $arr_3d[$inda] }).

i test , works. using fortran index notation (starting @ 1), changed c indexing (starting @ 0).

use data::dumper;  @arr_3d ;  $arr_3d[0][0][0] = 1;  $arr_3d[0][1][0] = 2;  $arr_3d[0][0][1] = 4;  $arr_3d[0][1][1] = 3;  $inda = 0;  $indc = 0;  @temp = @{ $arr_3d[$inda] };  @{ $arr_3d[$inda] } = sort { $b->[$indc] <=> $a->[$indc] } @temp;   print dumper(\@arr_3d); 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -