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.

  @array[map$_*2,0..$#array/2]

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

  @array[map$_*2-1,1..@array/2]

@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
necessary.

Smylers
-- 
http://twitter.com/Smylers2

Reply via email to