I would basically do what you do, except that I'd create the list of indices first, and then rearrange the target array:
my @foo = (1..8); my @indices = map { $_*2 +1 => $_*2 } 0..(@foo / 2)-1; @bar = @foo[ @indices ];
In reply to Re: Switch the odd/even elements of an array
by Corion
in thread Switch the odd/even elements of an array
by jaredor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |