in reply to Sorting multidimensional arrays using a list of indices
@{ $arr_1[$i][@indices] } should be @{$arr_1[$i]}[@indices] if you want to return a slice with the element order determined by @indices. Although you don't reference the line where the error is being reported nor give us enough code to actually reproduce your error, that is most likely where the issue is.
Aside from that, your final loop uses $e as a loop variable, but @arr_1 is indexed by the undeclared variable $i. Always use strictures (use strict; use warnings; - see The strictures, according to Seuss)!
Using Perl there are very few places where you need to resort to using a C for loop. Use a Perl for loop instead:
for my $i (0 .. $#suff) {...}
although the last loop in your sample code might be better written:
for my $elt (@arr_1) { @$elt = @{$elt}[@indices]; }
or even
@$_ = @{$_}[@indices] for @arr_1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Sorting multidimensional arrays using a list of indices
by eas2domine (Initiate) on Sep 10, 2009 at 14:01 UTC |