|Do you know where your variables are?|
Mystery state (possibly about whether an argument is numeric?) being maintained across calls to a subby cheesestraws (Novice)
|on Jun 15, 2013 at 13:44 UTC||Need Help??|
cheesestraws has asked for the
wisdom of the Perl Monks concerning the following question:
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.
Since xx has no side-effects except for output, there should be no state maintained between multiple calls to it.
However, what this code actually does seems to be depend on what version I'm running it under:
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 $arg's numeric status is somehow getting "stuck".
Putting a print inside the subroutine that prints $arg verifies that $arg is receiving the right value. Putting intermediate calls to other subroutines, or other code, in between the calls to xx doesn't seem to change anything, either.
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.
Can anyone shed some light on why this is happening?