Re: seeking golfing advice
Aristotle Pagaltzis <[email protected]> Thu, 17 May 2012 12:28:20 +0200
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
* Pau Amma <[email protected]> [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=E2=80=A6 but the latter w= orks 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.) --=20 *AUTOLOAD=3D*_;sub _{s/$/$"/;s/(.*):://;wantarray//substr$_,-1,1,",$/";pr= int;$1} &Just->another->Perl->hack; #Aristotle Pagaltzis // <http://plasmasturm.org/>