Re: seeking golfing advice

John Douglas Porter <[email protected]> Wed, 16 May 2012 04:40:40 -0700 (PDT)
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
And of course, use grep, as others have said.=0A=0A@list[ grep !$_%2, 0..$#=
list ];=0A=0Athat gets you every other element, beginning with the first.=
=0A=0A=0A--- On Wed, 5/16/12, John Douglas Porter <[email protected]> w=
rote:=0A=0A> From: John Douglas Porter <[email protected]>=0A> Subject:=
 Re: seeking golfing advice=0A> To: [email protected]=0A> Date: Wednesday, May 1=
6, 2012, 7:35 AM=0A> It's not clear whether you want=0A> "every other eleme=
nt, beginning with the first" or "every=0A> numeric element with the proper=
ty 'odd'".=A0 Your example=0A> doesn't clear that up at all. :-)=0A> =0A> I=
f it's the latter you want:=0A> =0A> map { $_ & 1 ? $_ : () } @l;=0A> =0A> =
=0A> --- On Wed, 5/16/12, damien krotkine <[email protected]>=0A> wrote:=
=0A> =0A> > From: damien krotkine <[email protected]>=0A> > Subject: Re: =
seeking golfing advice=0A> > To: [email protected]=0A> > Date: Wednesday, May 16=
, 2012, 7:19 AM=0A> > btw here is an example :=0A> > =0A> > the code, appli=
ed 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> > el=
ements of an=0A> > > array. The resulting list must have the same order=0A>=
 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=0A> nic=
er.=0A> > Everything in perl=0A> > > 5.12 is allowed, but must pass use str=
ict. I've=0A> failed=0A> > at using the=0A> > > '..' operator to act as a f=
lip/flop operator...=0A> > >=0A> > > thanks,=0A> > > dams=0A> >=0A>