Feature "show_numbers_strict" to display stringified numbers as strin… #178
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…gs ie. "10" and numbers as numbers ie. 10
Example with default behaviour (show_numbers_strict => "off"):
$ perl -Ilib -e 'use DDP; my $a = { a1 => "0", a2 => 0, c1 => "1.1", c2 => 1.1, d1 => 0x1234, d2 => "0x1234", e1 => -2.3, e2 => "-2.3"}; p $a;'
Printing in line 1 of -e:
{
a1: 0,
a2: 0,
c1: 1.1,
c2: 1.1,
d1: 4660,
d2: "0x1234",
e1: -2.3,
e2: -2.3
}
Example with show_numbes_strict => "on":
$ perl -Ilib -e 'use DDP show_numbers_strict => "on"; my $a = { a1 => "0", a2 => 0, c1 => "1.1", c2 => 1.1, d1 => 0x1234, d2 => "0x1234", e1 => -2.3, e2 => "-2.3"}; p $a;'
Printing in line 1 of -e:
{
a1: "0" (dualvar: 0),
a2: 0,
c1: "1.1" (dualvar: 1.1),
c2: 1.1,
d1: 4660,
d2: "0x1234" (dualvar: 0),
e1: -2.3,
e2: "-2.3" (dualvar: -2.3)
}
Why this PR?
The reason for this PR is because i was testing language development statements (BNF) and one of this language statements is '+'... which can be used to sum numbers, however on that language, similar like JS, it can also be used to concatenate strings.
1+2 = 3
1+'abc' = '1abc'
"22" + "44" = "2244"
During development, DDP has been used to debug the values and during the tests on that language numbers were concatenating instead of addition. And it was difficult to understand initially why that was happening because DDP showed stringified numbers as numbers without quotes. It was decided to check Data::Dumper output and turns out Data::Dumper shows numbers types more "correct", however Data::Dumper also seems to stringify non integers (floats for example.. probably because it would concatenate when evaluated back into an object in perl because of the dots '.')
Example Data::Dumper output:
perl -e 'use Data::Dumper; my $a = { a1 => "0", a2 => 0, c1 => "1.1", c2 => 1.1, d1 => 0x1234, d2 => "0x1234", e1 => -2.3, e2 => "-2.3"}; warn Dumper $a; '
$VAR1 = {
'a1' => '0',
'a2' => 0,
'c1' => '1.1',
'c2' => '1.1',
'd1' => 4660,
'd2' => '0x1234'
'e1' => '-2.3',
'e2' => '-2.3',
};
So this PR makes Data::Printer output numbers and numbers stringified more similar to data::Dumper.