my $t = 1; grep { $t^=1 } LIST
If you're on perl-5.10 or newer, you can also use a state variable inside the block, and thus not "tainting" the outer scope:
use 5.010; say grep { state $t = 1; $t ^= 1} <a b c d>; # prints: bd
In reply to Re: Mini-Tutorial: Working with Odd/Even Elements
by moritz
in thread Mini-Tutorial: Working with Odd/Even Elements
by ikegami
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |