It seems that printing a hash value to a file may change something internally.
The following code snippet will print (notice there is double quote around 1.6):
{"john":4,"mary":"1.6"}
Code snippet:
use JSON::XS;
$a = {};
$a->{john} += "4";
$a->{mary} += "1.6";
open ($fd, ">tmp.txt") || die "Failed to open file to write $!\n";
print $fd "$a->{mary}";
close $fd;
$b = encode_json($a);
print "$b\n";
If I comment out the 3 lines on writing to a file in the above:
open ($fd, ">tmp.txt") || die "Failed to open file to write $!\n";
print $fd "$a->{mary}";
close $fd;
it will print without double-quote around 1.6.
{"john":4,"mary":1.6}
My perl is 5.14.2 running on Ubuntu 12.04 64bit, the JSON::XS module has version 3.01.
Wonder if what is causing this. Thanks.