Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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

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 rifling through the Monastery: (6)
As of 2016-08-31 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (427 votes). Check out past polls.