I've not used perl for a while, but try something like this:
$tmp = $number % 2; if ($tmp == 1) { # ODD } else { # EVEN }
'
the percent sign (in PHP anyway) is MOD or modulus. Modulus returns the remander of a division opperation. So the remainder of 2/2 is 0, but the remainder of 3/2 is 1.
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.
Mark Hensler posted this at 21:44 — 28th September 2001.
He has: 4,048 posts
Joined: Aug 2000
ehh.. hmm..
I've not used perl for a while, but try something like this:
$tmp = $number % 2;
if ($tmp == 1) {
# ODD
}
else {
# EVEN
}
the percent sign (in PHP anyway) is MOD or modulus. Modulus returns the remander of a division opperation. So the remainder of 2/2 is 0, but the remainder of 3/2 is 1.
Mark Hensler
If there is no answer on Google, then there is no question.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.