The stupid question is the question not asked | |
PerlMonks |
Why do $x="$h->{foo}" and $x=$h->{foo} have different effects (as reported by Devel::Peek)?by ELISHEVA (Prior) |
on Mar 25, 2009 at 16:29 UTC ( [id://753172]=perlquestion: print w/replies, xml ) | Need Help?? |
ELISHEVA has asked for the wisdom of the Perl Monks concerning the following question: I always thought an assignment was an assignment, but I guess I'm wrong. I wonder if anyone can explain to me why the following two sets of assignments generate different results for PV (when dumped via Devel::Peek)? This issue came up because,
I might have thought that the datum assigned via direct assignment and interpolation might be different. But if that was so, why then do the following two bits of code also produce different results? We haven't (in Perl) actually assigned anything and yet the mere fact of using the variable in an interpolation seems to change it:
I've written a sample script to illustrate the differences and provided sample output from my machine (running Debian-Etch, Perl 5.8.8):
outputs the following:
Many thanks in advance, beth Update: added explanation of why this became an issue for me. Update: corrected intro paragraph (with strikeout). With the help of kyle and ikegami I now have a much better understanding of the Devel::Peek output. It appears that my first impression (that Storable was ignoring flags and preferring PV was wrong. Storable does indeed choose between IV and PV correctly. The differences I was seeing was because it also seems to be storing the flags along with the value. So if something changes the flags the output of Storable::freeze(...) changes as well, even if the actual value stored does not. This doesn't appear to be a bug, but it is something to be aware of if one ever needs to work with frozen strings. Once again, many thanks for the wonderful explanations all have provided. I have learned a great deal from this thread. Best, beth
Back to
Seekers of Perl Wisdom
|
|