CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
finding odd/even numbers

 



Grizz
Deleted

Feb 3, 2001, 10:45 PM

Post #1 of 5 (195 views)
finding odd/even numbers Can't Post

I'm trying to distinguish odd/even nums in a foreach. Something like this;
if($count == evennums){do this}
else{do this}
I tried if($count == [1,3,5,7]) but it was a wild guess and didn't work.I want to alternate bgcolors in table rows.
Thanks




kencl
User

Feb 4, 2001, 2:02 AM

Post #2 of 5 (192 views)
Re: finding odd/even numbers [In reply to] Can't Post

I use a conditional statement:

Code
$bgcolor = "green"; 
($bgcolor eq "green")?($bgcolor = "red"):($bgcolor = "green");

Tada!

>> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!


muinatit
Deleted

Feb 4, 2001, 5:42 AM

Post #3 of 5 (190 views)
Re: finding odd/even numbers [In reply to] Can't Post

Well if there was somehow a way to get the factors of 2 in Perl, you'd have no problem. Otherwise you might be stuck creating a huge array of even numbers.



Jasmine
Administrator / Moderator

Feb 4, 2001, 2:21 PM

Post #4 of 5 (186 views)
Re: finding odd/even numbers [In reply to] Can't Post

Check out my reply to the same question at Re: Should be easy question finding odd & even integer



Grizz
Deleted

Feb 4, 2001, 7:45 PM

Post #5 of 5 (179 views)
Re: finding odd/even numbers [In reply to] Can't Post

OK great.. Thanks for the help.


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives