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

Re: seeking golfing advice

Thread Previous
May 19, 2012 03:19
Re: seeking golfing advice
Message ID:
Aristotle Pagaltzis writes:

> And if you have an array to work with in the first place, you can also
>     @array[map 1+$_*2, 0..$#array/2]
> which is 3 characters longer than the grep version

I think that actually gives you the even elements. For the odd elements
(which are even array indices, in Perl's terms) you don't need the C<
1+> in there, saving 3 characters.


The shortest variant like that I've found for even characters is:


@array is one character shorter than $#array, but to avoid getting an
unwanted undef element when @array has an even number of elements in it
you need to start at 1 rather than 0, which makes the subtraction


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