* Pau Amma <paua...@gundo.com> [2012-05-16 14:55]:
> If, as it sounds, you want to balance golfiness and strictness, you
> could also say:
>
> @array[grep $_%2, keys @array]
>
> (or @array[grep $_%2^1, keys @array] if you set $[ to 1 - but you
> didn't do that, right? :-) )

Btw, `keys@foo` and `0..$#foo` are equally long… but the latter works
with old perls (advantage production) *and* looks more line-noisy
(advantage golf).

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 in exchange for doing
half as much work. (For even elements, the map and grep solutions would
yield exactly equally long code, with half-as-much-work still applying.)

-- 
*AUTOLOAD=*_;sub _{s/$/$"/;s/(.*):://;wantarray//substr$_,-1,1,",$/";print;$1}
&Just->another->Perl->hack;
#Aristotle Pagaltzis // <http://plasmasturm.org/>

Reply via email to