Syntactic Confectionery Delight | |
PerlMonks |
Re^3: Why do $x="$h->{foo}" and $x=$h->{foo} have different effects (as reported by Devel::Peek)?by ikegami (Patriarch) |
on Mar 25, 2009 at 17:46 UTC ( [id://753189]=note: print w/replies, xml ) | Need Help?? |
Using the output of your first snippet as an example,
The type of the scalar is promoted as necessary. Downgrading would be a waste of time, so flags are used to indicate what kind of value the scalar contains. Note that it's possible to have a scalar that has both an IV and PV.
When both IV and PV exist (i.e. when the scalar is a PVIV or subtype), or when POK is set? The former would definitely be a bug. Otherwise, read on. If a scalar contains both a number and a string (POK and either IOK or NOK), the situation is intended to be one of the following (and almost always is):
If we accept that more general dualvars can't be stored, we should be able to store only one of the string or the number. So which one should we used when?
As such, always storing the string is sufficient and appropriate. Update: Storing the string instead of the number also allows us to store '0 but true' and '0E0', true values that evaluate to zero.
In Section
Seekers of Perl Wisdom
|
|