swampyankee asked whether I would consider this a bug to be filed against Data::Dumper.  As I have no decided opinion on the matter, I'd like to pass the question on to all of you...   Essentially, I see two issues:

(1) Data::Dumper promises

(...) The return value can be "eval"ed to get back an identical copy of the original reference structure.

However:

use Data::Dumper; use Devel::Peek; my $foo = { num => 123.1 }; Dump $foo->{num}; my $serialised = Dumper $foo; $foo = eval $serialised; # deserialise Dump $foo->{num}; __END__ SV = NV(0x669d40) at 0x63c430 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 123.1 <-- originally, it's a number SV = PV(0x63d918) at 0x742c80 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x6650d0 "123.1"\0 <- it's a string now, when deserialised... CUR = 5 LEN = 8

But what would you consider "identical"...? I.e. does internal representation really matter, as Perl would automagically convert under most circumstances, anyway?

(2) It's not exactly good manners to silently modify data structures under the hood, when being passed them just for dumping purposes (this could cause unexpected issues with copy-on-write semantics with forked processes — such as when trying to preload libs/data to be shared across processes, in order to keep memory usage low (mod_perl comes to mind...)).  OTOH, this is not the only case in Perl where such things do happen...

So, whuttaya think?


In reply to Re^2: Need some wisdom on strings to numbers by almut
in thread Need some wisdom on strings to numbers by decebel

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.