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:
odd/even

 



spaz
Novice

Jan 23, 2001, 8:58 AM

Post #1 of 2 (232 views)
odd/even Can't Post

Is there a way for perl to tell if a number is an odd one or an even one? I'm trying to display information in lines with alternating colors. For example, the first <TR> line would have bgcolor=green; the next <TR> would have bgcolor=white; and then back to green and so on.

Spaz



japhy
Enthusiast

Jan 23, 2001, 10:00 AM

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

No. Of course not. Perl has no way of telling if a number is even or odd, even if you try taking that number modulus 2 to see if there's a remainder. (HINT HINT)


Code
use less 'helplessness'; 

if ($num % 2) { odd }
else { even }

Jeff "japhy" Pinyan -- accomplished hacker, teacher, lecturer, and author

 
 


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

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