in reply to Need some wisdom on strings to numbers
This seems to be a weird artifact of Data::Dumper's processing:
#!/usr/bin/perl use Data::Dumper; use Devel::Peek; my $store = {}; my $numString2 = '123.10'; my $num2 = $numString2+0; Dump $num2; #1 $store->{'num2'}=$num2; Dump $store->{'num2'}; #2 print Dumper $store; #3 Dump $store->{'num2'}; #4 __END__ SV = NV(0x636e40) at 0x604fd0 #1 REFCNT = 1 FLAGS = (PADBUSY,PADMY,NOK,pNOK) NV = 123.1 SV = NV(0x636e50) at 0x604410 #2 REFCNT = 1 FLAGS = (NOK,pNOK) NV = 123.1 $VAR1 = { #3 'num2' => '123.1' }; SV = PVNV(0x6b42f8) at 0x604410 #4 REFCNT = 1 FLAGS = (NOK,POK,pNOK,pPOK) IV = 0 NV = 123.1 PV = 0x6eb260 "123.1"\0 <-- side effect of dumping it with Data::D +umper CUR = 5 LEN = 40
As you can see in Devel::Peek's output, $num2 initially is a number only (no PV), but after dumping it with Data::Dumper, the string representation has been added to the scalar. And apparently, Data::Dumper then also prefers the string representation for its output...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Need some wisdom on strings to numbers
by almut (Canon) on Oct 07, 2009 at 14:55 UTC | |
by swampyankee (Parson) on Oct 09, 2009 at 21:17 UTC |