in reply to Why do $x="$h->{foo}" and $x=$h->{foo} have different effects (as reported by Devel::Peek)?
I'm no expert on Perl internals, so take what I say with some salt.
That said, I think I have an idea about what's going on here. A scalar in Perl can have a number or a string in it, and Perl will convert back and forth between them as necessary. The structure that Perl uses for a scalar has a pointer for a string and a pointer for a number, and it has flags to show which are valid representations of this scalar. That way, if you stored a string, and it converted it to a number, it can hold both of them and know that they're both valid and not have to do the conversion again. When you store a string or a number, the other pointer is marked as invalid but not actually changed.
You can see this in your tests. The pointers to values are IV and PV for numbers and strings, respectively. The flags for their validity are p?IOK and p?POK.
Lets look at the test.
The only time this string/numeric duality ever bit me was the time I documented in Strings and numbers: losing memory and mind.. Long story short, having both representations of something laying around takes a little extra memory, and I had a lot of scalars with both values set.
|
|---|