Peter Makholm <pe...@makholm.net> writes:

> damien krotkine <dkrotk...@gmail.com> 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;

Wow, you asked for golfing advice in the subject and a nice solution in
the actual text. Those requirements are quite often very incompatible.

> 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

This is probably as nice as it gets. For strictness I would just declare
$f as a lexical variable just outside the grep. But asking for golfing
advice is not compliant with strictness or niceness.

> And remove unneeded syntax
>
>   grep$|--,@array

I think this would be the golfing solution, but as with everything alse
related to perl golfing don't use it in production code.

//Makholm

Reply via email to