Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
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?
[ambrus]: herecy! meat (especially ground meat) and tomato together is a great basic recipe for various foodstuff. it's dairy product based sauces and tomato sauce that don't belong together.

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (10)
As of 2017-11-22 11:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (319 votes). Check out past polls.

    Notices?