Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
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 wandering the Monastery: (12)
As of 2014-09-17 16:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (91 votes), past polls