The following reverses an array in place, in case that's what you want:
sub reverse_inplace { for ( my $i = 0; $i < $#_ / 2; $i++ ) { my $j = $#_ - $i; @_[$i,$j] = @_[$j,$i]; # swap } } # try it: my @a = ( 1 .. 9 ); reverse_inplace( @a ); print "@a\n";
Originally posted as a Categorized Answer.
In reply to Re: How do I reverse array elements?
by rajib
in thread How do I reverse array elements?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |