Kc12349 has asked for the wisdom of the Perl Monks concerning the following question:
Hello All,
Why is a NV and IV created in this case as opposed to just an IV? If instead $scalar2 is set to '0', only an IV is created.
Additionally, why is NV used to track numeric value for $scalar1 when it is modified and not IV? If $scalar2 is instead set to '0' initially, numeric value will be stored in IV.
Thanks for any enlightenment you can offer.
use Devel::Peek; my $scalar1 = ''; Dump($scalar1); my $temp1 = $scalar1+1; Dump($scalar1); $scalar1 = $scalar1+1; Dump($scalar1); SV = PV(0x36974) at 0x43ef74 REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x2b23ad4 ""\0 CUR = 0 LEN = 4 Argument "" isn't numeric in addition (+) at C:\Projects\test.pl line +17. SV = PVNV(0x2bbc254) at 0x43ef74 REFCNT = 1 FLAGS = (PADMY,POK,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x2b23ad4 ""\0 CUR = 0 LEN = 4 SV = PVNV(0x2bbc254) at 0x43ef74 REFCNT = 1 FLAGS = (PADMY,NOK,pNOK) IV = 0 NV = 1 PV = 0x2b23ad4 ""\0 CUR = 0 LEN = 4 ### my $scalar2 = '0'; Dump($scalar2); my $temp2 = $scalar2+1; Dump($scalar2); $scalar2 = $scalar2+1; Dump($scalar2); SV = PV(0xa26974) at 0x2965d3c REFCNT = 1 FLAGS = (PADMY,POK,pPOK) PV = 0x2aa9cd4 "0"\0 CUR = 1 LEN = 4 SV = PVIV(0x43297c) at 0x2965d3c REFCNT = 1 FLAGS = (PADMY,IOK,POK,pIOK,pPOK) IV = 0 PV = 0x2aa9cd4 "0"\0 CUR = 1 LEN = 4 SV = PVIV(0x43297c) at 0x2965d3c REFCNT = 1 FLAGS = (PADMY,IOK,pIOK) IV = 1 PV = 0x2aa9cd4 "0"\0 CUR = 1 LEN = 4
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is the distinction between IV and NV variables?
by derby (Abbot) on Sep 06, 2011 at 20:45 UTC | |
|
Re: What is the distinction between IV and NV variables?
by ikegami (Patriarch) on Sep 06, 2011 at 22:39 UTC |