http://www.perlmonks.org?node_id=661703


in reply to Seeing if two numbers have the same sign

You are doing more work than you need to. Remember that mathematical comparisons return booleans, and booleans can be directly compared.

if ($x<0 == $y<0) { print "$x and $y have the same sign"; }

(($x ^ $y) < 0) would probably also work assuming they are integers. I think the trick with abs or the comparison operator would probably actually be less efficient than doing a comparison. Using multiplication is going to be slow as well.

BTW the sign of zero isnt a theological debate, it is an implementation detail of the machine you are working on and the data types you are using. :-)

---
$world=~s/war/peace/g