perlquestion cheesestraws <p>Here's a minimal test case that reliably reproduces a problem I've been having. As I understand perl, the three sets of print statements ought to produce the same output each time.</p> <code> use strict; no warnings "numeric"; print "Reusing one variable:\n"; my $val = "ff"; print "(" . ($val & "") . ")\n"; $val = 7; print "(" . ($val & "") . ")\n"; $val = "ff"; print "(" . ($val & "") . ")\n"; print "\n"; print "Using multiple variables:\n"; my $v1 = "ff"; print "(" . ($v1 & "") . ")\n"; my $v2 = 7; print "(" . ($v2 & "") . ")\n"; my $v3 = "ff"; print "(" . ($v3 & "") . ")\n"; print "\n"; print "Using a sub:\n"; sub xx { my $arg = shift; print "(" . ($arg & "") . ")\n"; } xx("ff"); xx(7); xx("ff"); </code> <p>Since <c>xx</c> has no side-effects except for output, there should be no state maintained between multiple calls to it.</p> <p>However, what this code actually <i>does</i> seems to be depend on what version I'm running it under:</p> <ul> <li>Under 5.16.3 i386-openbsd and 5.14.2 x86_64-linux-gnu-thread-multi, it does what I'd expect, giving the output: <code> Reusing one variable: () (0) () Using multiple variables: () (0) () Using a sub: () (0) () </code> </li> <li>Under versions before 5.14, though, I get a different result (tested on v5.10.0 darwin-thread-multi-2level, 5.10.1 i486-linux-gnu-thread-multi and 5.12.4 darwin-thread-multi-2level, which are the versions I currently can get access to): <code> Reusing one variable: () (0) () Using multiple variables: () (0) () Using a sub: () (0) (0) </code> </li></ul> <p>The output of the last set of prints no longer matches the previous two sets, which suggests that there's some state being preserved between calls to the sub. It looks a bit like <c>$arg</c>'s numeric status is somehow getting "stuck".</p> <p>Putting a print inside the subroutine that prints <c>$arg</c> verifies that <c>$arg</c> is receiving the right value. Putting intermediate calls to other subroutines, or other code, in between the calls to <tt>xx</tt> doesn't seem to change anything, either.</p> <p>I've trudged my way through the perldeltas between 5.12 and 5.14 and I couldn't see anything relevant, but then I don't really know what it'd come under, and I don't know much about the innards of perl, so it's possible I've completely missed something.</p> <p>Can anyone shed some light on why this is happening?</p> <p>Thanks!</p>