Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Find odd/even elements of array

by AnomalousMonk (Canon)
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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://930508]
help
Chatterbox?
[marioroy]: Is List::Util::XS a core Perl module?
[stevieb]: corelist List::Util::XS says "List::Util::XS was first released with perl v5.10.1"
[stevieb]: so yes, since v5.10.1 :)
[MidLifeXis]: According to [metaperl:// corelist], Perl 5.10.1
Lady_Aleena blurbles. One of her favorite modiles is now in "maintenance mode" in favor of a new fangled module.
[MidLifeXis]: D'oh. Slow out of the gate.
[marioroy]: Thanks stevieb, MidLifeXis.

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (12)
As of 2017-05-24 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?