in reply to "force string context"?
The assignments to $n1 and $n2, happening in numeric context, cause a loss of precision -- as well as removal of leading zeros, but using $s1 and $s2 in a numeric context does not cause a change in the string value that was originally assigned to these variables: if a variable is originally assigned a value in a string context, it will always return that value when used in a string context.$s1 = "01234567891233456789"; $s2 = "012345.6789123456789"; $n1 = $s1+1; $n2 = $s2+1; $c1 = $s1; $c2 = $s2; print "$n1 == $s1 + 1\n"; print "$n2 == $s2 + 1\n"; print "$c1 eq $s1\n"; print "$c2 eq $s2\n"; __OUTPUT__ 1.23456789123346e+18 == 01234567891233456789 + 1 12346.6789123457 == 012345.6789123456789 + 1 01234567891233456789 eq 01234567891233456789 012345.6789123456789 eq 012345.6789123456789
The other thing to note is that the "default" value assignment operation is a string assignment, unless rhs variable's original value was obtained/created in a numeric context.
|
|---|