"be consistent" | |
PerlMonks |
Re: YAML scalar ref strange behavior (JSON++)by tye (Sage) |
on Jun 04, 2014 at 02:45 UTC ( [id://1088558]=note: print w/replies, xml ) | Need Help?? |
Yeah, YAML has such an unreasonably large spec that it ends up having plenty of room for unpleasant surprises. (It also is too large of a spec for any single person to ever even come close to fully understanding it so nobody can correctly implement it so you get disagreement on even fairly simple things between implementations, IME.) But, no, \99 in a loop isn't guaranteed to give you references to distinct scalars, as is easily shown:
But YAML then makes the problem worse. We start out with two distinct scalars each holding references to the same constant. YAML turns that into the two hash values being aliases to the same scalar (holding a single reference to the scalar value of 99). Clearly, the YAML spec needs some additions so that distinct references to the same scalar can be encoded differently than a single reference being held in two aliases within the data structure. ;) I can't tell you how to fix the problem as you are quick to rule out the likely ways one would fix the problem so I suspect you'll likely rule out any fix I might suggest. Several alternate fixes seem easy to come up with, so my guess is you aren't considering those as you have reason to eliminate them. Though, I certainly encourage you to start to move to JSON (which has a spec so tiny that it borders on being trivial to understand -- other than some slight complexity around character encoding details that often just don't matter). I very much don't want my "transfer data" encoding to support the concept of aliases, which is just one of the many reasons that I like JSON. - tye
In Section
Seekers of Perl Wisdom
|
|