in reply to Re^2: check if 2 values are equal
in thread check if 2 values are equal

My solution is wrong, but for different reasons. eq cannot replace ==:

$a = "01000"; $b = 1000; printf "\$a eq \$b : %s\n", $a eq $b; printf "\$a == \$b : %s\n", $a == $b;

use strict; has no bearing on comparisons. What you are thinking of is use warnings;, which will warn about non-numeric values being compared with ==.

Replies are listed 'Best First'.
Re^4: check if 2 values are equal
by clinton (Priest) on Jan 24, 2006 at 19:40 UTC
    Re use warnings rather than use strict - thanks for the correction.

    Likewise, you are right about the "0100" not being equal to 100, which is what I meant about being sure that the values are represented internally as numbers.

    So if you said:

    $a = "01000"; $b = 1000; print $a eq $b ? 1 : 0; > 0 $a=$a+0; print $a eq $b ? 1 : 0; > 1