The stringified form also depends if the values began as strings or numbers.
Result is:$x = '1e-3'; $y = 0.001; if ( $x eq $y ) { print "$x and $y are equal.\n" } else { print "$x and $y are not equal" } print "\n"; $x = $x + 0; if ( $x eq $y ) { print "$x and $y are equal.\n" } else { print "$x and $y are not equal" }
1e-3 and 0.001 are not equal 0.001 and 0.001 are equal.
In the first comparison, $x is a string. In the second comparison, $x is numeric before it is stringified for comparison.
The Scalar::Util documentation is useful here. https://perldoc.perl.org/Scalar/Util.html#isdual
In reply to Re^2: Why does this string comparison compares "numerically" and can I rely on this in general?
by swl
in thread Why does this string comparison compares "numerically" and can I rely on this in general?
by Bloehdian
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |