AW: seeking golfing advice

Moritz, Georg <[email protected]> Wed, 16 May 2012 13:51:18 +0200
Newsgroups gmane.comp.lang.perl.fun
Message-ID <[email protected]>
> btw here is an example :
>=20
> the code, applied on (1, 2, 3, 4) would return (1, 3). Thanks

so you want to check every element for oddity of its value, not its index, right=3F

@list =3D grep{$_%2}@array;

cheers,
0--gg-

> On 16 May 2012 13:15, damien krotkine <[email protected]> wrote:
> > Hi,
> >
> > 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) } =C2=A0@array;
> >
> > I'm looking for advice to make it shorter or nicer. Everything in perl
> > 5.12 is allowed, but must pass use strict. I've failed at using the
> > '..' operator to act as a flip/flop operator...
> >
> > thanks,
> > dams
>