Subject: | Unexpected behaviour after assigning undef to a scalar which had previously been passed to json_decode |
$ perl -v
This is perl, v5.10.0 built for x86_64-linux-gnu-thread-multi
$ perl -MJSON::XS -le 'print $JSON::XS::VERSION'
2.3
I really don't know what's going on here. This might not be a bug for
JSON::XS, but it's a bug for -something- and I'd appreciate any help in
tracking down the right something.
When I decode_json some $var, then set $var to an undefined value, then
decode_json the same $var, I get the first results back, as if $var
hasn't changed (it has. I checked. I promise).
Note that if I 'undef $var;' first, instead of '$var = <something
returning an undefined value>', I get correct results (decode_json
throws an exception).
Test cases:
This isn't right:
perl -MJSON=decode_json -MData::Dumper -le 'sub blah { my $c; } my $h =
"{\"a\":1}"; my $one = decode_json($h); print \$h; $a = blah(); print
\$h; $two = decode_json($h); print Dumper($one); print Dumper($two);'
SCALAR(0x125a948)
SCALAR(0x125a948)
$VAR1 = {
'a' => 1
};
$VAR1 = {
'a' => 1
};
This is just fine:
$ perl -MJSON=decode_json -MData::Dumper -le 'my $h = "{\"a\":1}"; my
$one = decode_json($h); print \$h; undef $h; print \$h; $two =
decode_json($h); print Dumper($one); print Dumper($two);'
SCALAR(0x11ecf10)
SCALAR(0x11ecf10)
malformed JSON string, neither array, object, number, string or atom, at
character offset 0 (before "\x{0}\x{0}\x{0}\x{0}...") at -e line 1.
I'm told:
"I can reproduce it with perl-5.12.3 on Mandriva Linux Cooker."
"unable to reproduce on perl v5.12.3 with JSON 2.53 [...] though i'm on
OS X"
(perl-5.14.1) "yes, I can reproduce the bug after I installed JSON::XS"