develooper Front page | perl.perl5.porters | Postings from December 2008

[perl #61754] 'Data::Dumper' reports double value as string.

Thread Previous | Thread Next
From:
reneeb via RT
Date:
December 29, 2008 08:08
Subject:
[perl #61754] 'Data::Dumper' reports double value as string.
Message ID:
rt-3.6.HEAD-26531-1230560867-371.61754-15-0@perl.org
On Sa. 27. Dez. 2008, 02:40:54, grian wrote:
> [Please enter your report here]
> 
> $ perl -MData::Dumper -e'print Dumper(1.0)'
> $VAR1 = '1';
> must be:
> $VAR1 = 1;
> 
> ===Note single quotes===
> 

Is this really a bug?

I know that the behaviour differs with Dumper.xs and Dumper.pm.

This is current behaviour:

C:\>perl -MData::Dumper -e "print Dumper 1.0"
$VAR1 = '1';

C:\>perl -MData::Dumper -e "print Dumper 1.01"
$VAR1 = '1.01';

C:\>perl -MData::Dumper -e "$Data::Dumper::Useperl=1; print Dumper 1.01"
$VAR1 = '1.01';

C:\>perl -MData::Dumper -e "$Data::Dumper::Useperl=1; print Dumper 1.0"
$VAR1 = 1;

C:\>perl -MData::Dumper -e "$Data::Dumper::Useperl=1; print Dumper
123456789.0"
$VAR1 = 123456789;

C:\>perl -MData::Dumper -e "$Data::Dumper::Useperl=1; print Dumper
1234567890.0"
$VAR1 = '1234567890';

You can see that even with the Perl implementation of Dumper it uses
single quotes if the number has more than 9 digits. This is due to this
line: 

    elsif ($val =~ /^(?:0|-?[1-9]\d{0,8})\z/) { # safe decimal number
      $out .= $val;
    }

If you want to get rid of the single quotes for decimals that ends with
".0" you have to remove the differentiation of Perl < 5.6 and Perl > 5.6
for the "DD_is_integer" definition in Dumper.xs.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About