Re: seeking golfing advice
[email protected] (Peter Makholm) Wed, 16 May 2012 13:30:43 +0200
| Newsgroups | perl.fwp |
|---|---|
| Message-ID | <[email protected]> |
damien krotkine <[email protected]> writes: > I'm using this code to get a list of only the odd elements of an > array. The resulting list must have the same order as the array. > > map { state $f; ($_) x (++$f%2) } @array; If you want only to get some elements of a list is is much more obvious to use grep instead of map: grep { ++$f%2 } @array Then use the magical flip-flop variable: grep { $|-- } @array And remove unneeded syntax grep$|--,@array //Makholm