Perl Monk, Perl Meditation | |
PerlMonks |
Re: Checking for odd/even numberby perlmonkey (Hermit) |
on May 28, 2000 at 11:07 UTC ( [id://15187]=note: print w/replies, xml ) | Need Help?? |
And you can inline the if/else using the ? : operators.
print $_ % 2 ? "$_ is odd\n" : "$_ is even\n" for (1..5)
Results: 1 is odd 2 is even 3 is odd 4 is even 5 is odd
In Section
Seekers of Perl Wisdom
|
|