in reply to Array manipulation how to

Let me add one more:

  • rotate an array left/right
  • # rotate @array left my $temp=shift @array; push(@array,$temp); # rotate @array right my $temp=pop @array; unshift(@array,$temp);

    Replies are listed 'Best First'.
    Re^2: Array manipulation how to
    by JavaFan (Canon) on Feb 07, 2012 at 11:32 UTC
      And without an additional variable:
      push @a, shift @a; unshift @a, pop @a;
        would this work?
        @_=@a; push, shift; @_=@a; unshift, pop;
          No, as that doesn't modify @a.