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

Re: Subroutine Even/Odd

by johngg (Abbot)
on Oct 04, 2012 at 08:11 UTC ( #997204=note: print w/ replies, xml ) Need Help??


in reply to Subroutine Even/Odd

Another way using push and a ternary.

$ perl -Mstrict -Mwarnings -E ' > my( @odds, @evens ); > push @{ $_ % 2 ? \ @odds : \ @evens }, $_ for 1 .. 10; > say qq{ Odds: @odds}; > say qq{Evens: @evens};' Odds: 1 3 5 7 9 Evens: 2 4 6 8 10 $

I hope this is of interest.

Update: Documentation link corrected, thanks choroba :-)

Cheers,

JohnGG


Comment on Re: Subroutine Even/Odd
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-07-29 04:01 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 (260 votes), past polls