in reply to Change elements order in an array

It works if you change the order in the first three elements - your array doesn't have elements with indices 4 and 5 (neither 3).
my @new_order = (2, 1, 0);

BTW, that's where the undef's were coming from.

Update: to change the order of the inner arrays, you have to slice the inner arrays:

my @new_aoa = map [ @$_[@new_order] ], @AoA;
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Replies are listed 'Best First'.
Re^2: Change elements order in an array
by Anonymous Monk on Oct 16, 2015 at 15:13 UTC
    This is what I am trying to get it:
    I asked to wrong way.
    $VAR1 = [ [ 'aaa', 'bbb', 'ccc', 'ddd', 'eee', 'fff' ], [ '111', '222', '333', '444', '555', '666' ], [ 'ppp', 'eee', 'rrr', 'lll', 'ooo', 'kkk' ], ];

      Please see Re: Change elements order in an array. This node has been merged with it, and this one will be reaped.

      Per part of my post in Re: Change elements order in an array, you're wanting to modify the inner arrays. This will work. Just put your original data back in. 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;