in reply to Re^2: Question on SV internals
in thread Question on SV internals

$s = '20 ducks';; Dump $s;; SV = PV(0x18aec0) at 0xa5b48 REFCNT = 1 FLAGS = (POK,pPOK) PV = 0x40cad18 "20 ducks"\0 CUR = 8 LEN = 16

Length = 16. Now use it in a numeric constant.

$s += 1;; Argument "20 ducks" isn't numeric in addition (+) at (eval 13) line 1, + <STDIN> line 4. Dump $s;; SV = PVNV(0x40b1eb8) at 0xa5b48 REFCNT = 1 FLAGS = (NOK,pNOK) IV = 20 NV = 21 PV = 0x40cad18 "20 ducks"\0 CUR = 8 LEN = 16

Hm. Length still 16, but we gained an IV = 20 and an NV = 21; so we gained 12 or 16 bytes.

Oh, and the PV no longer reflects the value of the scalar, so when you use it in a string context, a conversion has to happen!

print $s;; 21 Dump $s;; SV = PVNV(0x40b1eb8) at 0xa5b48 REFCNT = 1 FLAGS = (NOK,POK,pNOK,pPOK) IV = 20 NV = 21 PV = 0x40d3068 "21"\0 CUR = 2 LEN = 40

Which modifies the PV and oops, it grew to 40 bytes in the process.

And I don't care how you try to weasel out of it, the evidence is right there for those that care to look. So don't bother.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^4: Question on SV internals
by ikegami (Patriarch) on May 08, 2011 at 16:47 UTC

    Now use it in a numeric constant. $s += 1;

    $s += 1 does more than "use it in a numeric context".

    Update:

    Furthermore, even though you went outside the scope of the question, the scalar still has a numerical value throughout.

      FLAGS = (NOK,pNOK)
      FLAGS = (NOK,POK,pNOK,pPOK)

    There is no such terminating condition.

      does more than "use it in a numeric context".

      And of course, that could never happen in a real program. Take your blinkers off.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        So much misdirection! Are you still claiming the caching only lasts "until you next use it in a string context."? Why don't you show an example of this happening if so?