C:\>perl -e"print grep {++$a % 2} qw{a 1 b 2 c 3}" abc
Though their values will leak into the outer scope, so state is better for longer scripts.
FWIW: I always thought that an automatic loop-count variable $c or $^c would come very handy inside grep-like constructs.
Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery
In reply to Re^3: alternate array elements
by LanX
in thread alternate array elements
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |