Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature "show_numbers_strict" to display stringified numbers as strin… #178

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

hernan604
Copy link

@hernan604 hernan604 commented Apr 27, 2023

…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.

@hernan604 hernan604 changed the title initial "show_numbers_strict" to display stringified numbers as strin… Feature "show_numbers_strict" to display stringified numbers as strin… Apr 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant