eas2domine has asked for the wisdom of the Perl Monks concerning the following question:
This code continues to give the error: Can't use an undefined value as an ARRAY reference at analyze.pl for the sorting routine. How can I sort the second dimension of @arr_1? Is @arr_1 a 3D array in the way that I have coded it?#construct 2D array for (my $e = 0; $e < @dim1; $e++) { $arr_1[$e] = [ @array ]; } # fill array for (my $i = 0; $i < 10; $i++) { @tmp_array = undef; for (my $e = 0; $e < @suff; $e++) { $tmp_array[$e] = $e; } push @{ $arr_1[$i] }, [ @tmp_array ]; } # Get the indices from the sorted list @indices = sort { $arr2sort[$a] <=> $arr2sort[$b] } 0..$#arr2sort; # Sort the 3D array? for (my $e = 0; $e < @suff; $e++) { @{ $arr_1[$i] } = @{ $arr_1[$i][@indices] }; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sorting multidimensional arrays using a list of indices
by GrandFather (Saint) on Sep 10, 2009 at 02:22 UTC | |
by eas2domine (Initiate) on Sep 10, 2009 at 14:01 UTC | |
|
Re: Sorting multidimensional arrays using a list of indices
by Marshall (Canon) on Sep 10, 2009 at 03:08 UTC |