data-dump
data-dump copied to clipboard
Data::Dump::dump silently changes string to integer
Hi
I am using Data::Dump v1.23 and found issue that Data::Dump::dump sliently changes string to integer to cause YAML dump print incorrect result.
Here are the example code
use YAML::XS;
use Data::Dump;
my $data = { id => [ '0123', '0234']};
print "before dump\n";
print YAML::XS::Dump($data);
Data::Dump::dump($data);
print "after dump\n";
print YAML::XS::Dump($data);
And if i launch the script, you can find the second YAML::XS::Dump
print element in $data as integer.
$ perl testy.pl
before dump
---
id:
- '0123'
- '0234'
{ id => ["0123", "0234"] }
after dump
---
id:
- 0123
- 0234
Isn't this a bug in YAML::XS::Dump then?
It is not. because YAML::XS::Dump gives right answer before calling Data::Dump::dump
I'm a big fan of this module! But I do have to second this issue, as it's not just with YAML, it appears Data::Dump coerces the variables to numeric, silencing any following warnings, and causing them to behave a bit like a dualvar:
$ perl -wMstrict
use Data::Dump;
use Devel::Peek;
my $y = "4x";
dd $y;
print $y+3, " ", $y.3, "\n";
Dump($y);
__END__
"4x"
7 4x3
SV = PVNV(0x964262) at 0x984424
REFCNT = 1
FLAGS = (POK,IsCOW,pIOK,pNOK,pPOK)
IV = 4
NV = 4
PV = 0x993912 "4x"\0
CUR = 2
LEN = 10
COW_REFCNT = 1
It appears this is the same as RT#86592. Update: I see that Pull Requests #7 and #11 provide possible patches.
Using Data::Dump
with data structures later send to MongoDB also has some rather strange effects; e.g. strings like "Information"
being stored as numeric Inf
.
See https://jira.mongodb.org/browse/PERL-992 for more information.
This also causes issues with JSON::Validator.