Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Get even postion elements in an array

by pKai (Priest)
on Nov 16, 2010 at 16:16 UTC ( #871771=note: print w/replies, xml ) Need Help??


in reply to Get even postion elements in an array

@output = grep $|--, @input;

using some magic of $| for the flipflop.

But unless you use it for a real oneliner, use some less obscure formulation of the principal shown in previous replies. ;-)

Replies are listed 'Best First'.
Re^2: Get even postion elements in an array
by Anonymous Monk on Oct 20, 2016 at 01:25 UTC
    $ perl -e 'my @a=(2, 3, 4, 5, 1, 7); print ("==> ", (map{$_ % 2 ? (): +" $a[$_]"} 0..$#a), "\n");' ==> 2 4 1

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://871771]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2016-12-08 23:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (148 votes). Check out past polls.