in reply to Change elements order in an array

What are you trying to achieve? Please provide example output. The way you're doing it now is re-ordering the top-level array only. By adding the appropriate number of elements to the top level array, you can see the results:
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @new_order = (0, 1, 2, 3, 5, 4); my @AoA = ( [ 'zero', ], [ 'one', ], [ 'two', ], [ 'three', ], [ 'four', ], [ 'five', ], ); my @new_aoa = @AoA[@new_order]; print Dumper \@new_aoa; __END__ $VAR1 = [ [ 'zero' ], [ 'one' ], [ 'two' ], [ 'three' ], [ 'five' ], [ 'four' ] ];
If you're trying to re-sort the inner arrays, then the following should help, just replace the example data with your real structure... It iterates over @AoA, and for each array reference within it, slices it to the specified order, then pushes those results within a new array reference onto the @new_aoa structure.
my @new_order = (0, 1, 2, 3, 5, 4); my @AoA = ( [ qw(1 2 3 4 5 6), ], [ qw(a b c d e f), ], ); my @new_aoa; for (@AoA){ push @new_aoa, [@$_[@new_order]]; } print Dumper \@new_aoa;
-stevieb

Replies are listed 'Best First'.
Re^2: Change elements order in an array
by Anonymous Monk on Oct 16, 2015 at 15:25 UTC
    Thats what I was missing, "A loop".
    Thank you!