in reply to Bug or Feature?
But then you do a numerical comparison with $b. So $b's internal scalar caches $b's integer value along with its string value.
Now the second time you evaluate ($a & $b), $b has an integer value inside, so it is treated as an integer (this must the preference of bitwise operators?). By the table below, you can see that as long as one of the arguments to the "&" operator is considered to be an integer, we use the integer/bitwise version of the operator (and the result is 8 this time).
print "12" & "8", $/; # 0 print 12 & 8, $/; # 8 print 12 & "8", $/; # 8 print "12" & 8, $/; # 8
blokhead
|
|---|