"be consistent" | |
PerlMonks |
Re^6: The error says the value is uninitialized, but it works anywayby haukex (Archbishop) |
on Aug 18, 2019 at 10:19 UTC ( [id://11104650]=note: print w/replies, xml ) | Need Help?? |
Here is a look at the internals with Devel::Peek:
Here, you can see that the variable $a has both the string component PV = "1"\0, and it is marked as valid with POK, and an integer component IV = 1, also marked as valid with IOK. So they are both valid, and as I said, there is no reliable way to ask Perl for the difference. Modules like Data::Dumper have to guess what to output based on this internal information. (AFAICT from the source, the XS implementation of Data::Dumper simply prefers the integer version when that is valid. Other dumper modules handle such cases differently.) What's going on here?
As you can see, what happens in this case internally is that the postincrement keeps only the string component, while the postdecrement converts it to an integer. If I had to guess why this is is the case, it might have to do with the "magic string increment" feature. However, these are internal implementation details that one should not rely on!
In Section
Seekers of Perl Wisdom
|
|