Perl Monk, Perl Meditation | |
PerlMonks |
Re: Encountered object '5.03 ', but neither allow_blessed nor convert_blessed settings are enabledby davido (Cardinal) |
on Aug 13, 2015 at 16:55 UTC ( [id://1138453]=note: print w/replies, xml ) | Need Help?? |
First, you'll just end up confusing yourself again if you call a variable used to hold a datastructure "$json". Also, printing to a file is just adding unnecessary complexity that makes it harder to test. Just print, and see the output. Here's a small script with those adaptations:
The part after __END__ is the output I saw on my screen. It indicates that you are indeed getting 5.03, the number. Are you seeing different results? If so, it probably has to do with the heuristics that JSON::PP uses to decide if something is a number or a string. It might do some introspection to determine if the number has ever been used as a string. Examples of what can make Perl think internally that a scalar variable holds a string include obvious string operations such as concatenation, less obvious such as sprintf, and even the common case of using print. Your actual code may be something like pages => $number, but you may at one point have treated $number as a string. And in so doing, Perl starts thinking the variable holds a string (this is an internal process... an implementation detail leaking out). You can force numification by using a numerical operator at a carefully chosen time:
Now we're forcing numeric context on $number. Dave
In Section
Seekers of Perl Wisdom
|
|