Re: seeking golfing advice

[email protected] (John Douglas Porter) Wed, 16 May 2012 04:35:38 -0700 (PDT)
Newsgroups perl.fwp
Message-ID <[email protected]>
It's not clear whether you want "every other element, beginning with the fi=
rst" or "every numeric element with the property 'odd'".  Your example does=
n't clear that up at all. :-)=0A=0AIf it's the latter you want:=0A=0Amap { =
$_ & 1 ? $_ : () } @l;=0A=0A=0A--- On Wed, 5/16/12, damien krotkine <dkrotk=
[email protected]> wrote:=0A=0A> From: damien krotkine <[email protected]>=0A=
> Subject: Re: seeking golfing advice=0A> To: [email protected]=0A> Date: Wednes=
day, May 16, 2012, 7:19 AM=0A> btw here is an example :=0A> =0A> the code, =
applied on (1, 2, 3, 4) would return (1, 3).=0A> Thanks=0A> =0A> On 16 May =
2012 13:15, damien krotkine <[email protected]>=0A> wrote:=0A> > Hi,=0A> =
>=0A> > I'm using this code to get a list of only the odd=0A> elements of a=
n=0A> > array. The resulting list must have the same order as=0A> the array=
.=0A> >=0A> > map { state $f; ($_) x (++$f%2) } =A0@array;=0A> >=0A> > I'm =
looking for advice to make it shorter or nicer.=0A> Everything in perl=0A> =
> 5.12 is allowed, but must pass use strict. I've failed=0A> at using the=
=0A> > '..' operator to act as a flip/flop operator...=0A> >=0A> > thanks,=
=0A> > dams=0A>