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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |