develooper Front page | perl.fwp | Postings from May 2012

Re: seeking golfing advice

Thread Previous | Thread Next
Peter Makholm
May 16, 2012 04:31
Re: seeking golfing advice
Message ID:
damien krotkine <> 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



Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About