#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    California, USA
    Posts
    9
    Rep Power
    0
    Hello, I am writing to see if there is an even or odd function in PERL..

    What I'm trying to do is have alternating table backgrounds.... If even($x) { one color } else { 2nd color};

    something like that. Any help is appreciated.

    Thanks!
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Boston, MA
    Posts
    6
    Rep Power
    0
    I've addressed this before by using modulo math:

    if ($x % 2) {
    INSERT ODD STATEMENTS HERE
    } else {
    INSERT EVEN STATEMENTS HERE
    }

    (This essentially checks to see if there's a remainder when the number is divided by 2; if there is, than it's odd (hence 'true').)

    Hope this helps!

    Cheers,
    Yuccatan

    [This message has been edited by yuccatan (edited November 06, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Location
    California, USA
    Posts
    9
    Rep Power
    0
    Great! I didn't consider using MOD.

    Thanks a ton

IMN logo majestic logo threadwatch logo seochat tools logo