in reply to how do i test a number negative or positive?
For your original question, comparing with the abs value should do the trick ...
if ( $num == abs($num) ) { print "positive"; } else { print "negative"; }
... but for your revised question, you should check the modulus ...
if ( $num % 2 ) { print "odd"; } else { print "even"; }
However, if all you really want to do is alternate colours...
Edit by dws per author's request
|
|---|