Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
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?
[Your Mother]: Cumin? Now I want tacos...
[Eily]: there should be an option in grep for fuzzy order of the letters in the pattern
[Eily]: as in "I might have inverted two, but my eyes misread in the some order as my fingers mistype"
[LanX]: can't find a definition for the sound
[LanX]: Voiceless_palatal_ fricative
[Eily]: Lanx https://en. wikipedia.org/ wiki/Voiceless_pal atal_fricative
Eily got the Cowboy message

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (13)
As of 2017-03-27 17:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (320 votes). Check out past polls.