in reply to Mini-Tutorial: Working with Odd/Even Elements
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Mini-Tutorial: Working with Odd/Even Elements
by ikegami (Patriarch) on Jul 09, 2009 at 19:22 UTC | |
|
Re^2: Mini-Tutorial: Working with Odd/Even Elements
by JavaFan (Canon) on Jul 09, 2009 at 19:02 UTC | |
by salva (Canon) on Jul 09, 2009 at 19:14 UTC | |
by JavaFan (Canon) on Jul 09, 2009 at 19:33 UTC |