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

Re: seeking golfing advice

From:
Mike Erickson
Date:
May 16, 2012 06:41
Subject:
Re: seeking golfing advice
Message ID:
4FB3AE8B.8060600@quidquam.com
On 05/16/2012 07:46 AM, damien krotkine wrote:
> Hi all,
>
> thanks for the quick answers :)
>
> first of all, despite my attempt to clear things up with an example, I
> failed :)  What I wante is "every other element, beginning with the
> first", so :
>
> ( 'foo', 3, 42, 'bar) should become ( 'foo', 42).

If you don't care about order, but just want those elements, you can 
also do:

keys%{{@a}}

{@a}    being a hash ref constructed from @a
%{ }    dereferencing that hash ref
keys    pulling out the keys, ie. the odd elements of the orig. list

hth,

Mike




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About