Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Find odd/even elements of array

by AnomalousMonk (Abbot)
on Oct 09, 2011 at 22:34 UTC ( #930508=note: print w/ replies, xml ) Need Help??


in reply to Find odd/even elements of array

A pure-database approach seems best, but here's an array manipulation approach that's almost straight from the List::MoreUtils docs:

>perl -wMstrict -le "use List::MoreUtils qw(part); ;; my @si = qw(001 John 002 Mary 003 Tom); ;; my $i = 0; my @parts = part { $i++ % 2 } @si; print qq{even index elements: @{ $parts[0] }}; print qq{ odd index elements: @{ $parts[1] }}; " even index elements: 001 002 003 odd index elements: John Mary Tom


Comment on Re: Find odd/even elements of array
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930508]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2015-07-29 19:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (267 votes), past polls