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

In reply to What is the distinction between IV and NV variables? by Kc12349

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.