Abigail <abigail <at> abigail.be> writes: >>>>>>> $ perl -E '$a = $b = "abc100"; 0 + $b; say $a; say $b; >>>>>>> $a ++; $b ++; say $a; say $b' >>The numeric value could be cached in the scalar and used next time, >>but without flipping the switch to mark the scalar as numeric. Then >>later numeric context uses would be fast, but the value would not >>mysteriously change. >That would probably mean we have to use a bit (or two, or three, if >we want to use the same trick for floats and strings) in the very >limited supply of bits reserved in the SV structure, for a case >that's only seldom useful. Hmm. To my mind the example of C<map { $_ + $b } @a> is the case that's only seldom useful - or at least the speedup from mutating $b is relatively unimportant - whereas the guarantee that variable contents won't change without an explicit assignment (or ++, etc) is something to be absolutely respected. But this is very much a matter of opinion. If the example you mentioned is considered a bug, then spending a bit in every SV to fix it is a bargain. If it's not a bug, then the documentation of + and similar numeric operators in perlop needs to have some kind of caveat that just using them can affect the value of a scalar (though I don't know where exactly this should go). -- Ed Avis <eda@waniasset.com>Thread Previous | Thread Next