Re: seeking golfing advice

2012-05-17 Thread Aristotle Pagaltzis
* Mike Erickson m...@quidquam.com [2012-05-16 15:45]:
 If you don't care about order, but just want those elements, you can
 also do:

 keys%{{@a}}

There is more than order that gets lost. If you use `keys` you also get
everything back stringified – undefs are lost and references break. If
you use `values` these problems go away… except that to get the odd-
index elements from it you have to `reverse` the array, at which point
a not-especially-golfed grep is shorter.

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


Re: seeking golfing advice

2012-05-17 Thread Aristotle Pagaltzis
* 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/