When one stringifies a scalar, the string is attached to the scalar as an optimisation. It doesn't remove the existing number. This isn't a bug in D::D, but it doesn't mean that D::D couldn't be changed to avoid adding a string to the scalar. It already does in other circumstances.

(pPOK = has string) >perl -MDevel::Peek -MData::Dumper -e"$_=0.42; Dumper($_); Dump($_);" SV = NV(0x3335fc) at 0x328fe4 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 0.42 >perl -MDevel::Peek -MData::Dumper -e"$_={ qux => 42 }; Dumper($_); Du +mp($_->{qux});" SV = IV(0x57b260) at 0x57b264 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 42 >perl -MDevel::Peek -MData::Dumper -e"$_={ qux => 0.42 }; Dumper($_); +Dump($_->{qux});" SV = PVNV(0x5490e4) at 0x25b264 REFCNT = 1 FLAGS = (NOK,POK,pNOK,pPOK) IV = 0 NV = 0.42 PV = 0x4c9f84 "0.42"\0 CUR = 4 LEN = 36

The problem is that JSON doesn't allow you to specify how to handle a variable that's both a float and a string.


In reply to Re: Data::Dumper turns floating points numbers into strings by ikegami
in thread Data::Dumper turns floating points numbers into strings by Hue-Bond

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.