in reply to Re^2: Get even postion elements in an array
in thread Get even postion elements in an array
Here not is indeed more readable, but it won't produce 0 for false, which could be counterintuitive in other cases.
$flipflop needs to be declared, while $a (and $b) is already global as part of the sort idiom, which is a similar case of using a code block.
$a=1; my @result = grep { $a = not $a }, @input;
At the end it's a matter of taste. ^= is shorter, = not is clearer, but =1- can equally be used in most other languages, making it an universally understood idiom.
Cheers Rolf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Get even postion elements in an array
by anonymized user 468275 (Curate) on Nov 16, 2010 at 16:22 UTC |