So you want $sv->PV() to return a true value while you also want PV to not be set in the Dump() output? I am going to assume that your "should this be set?" comment just gave me an incorrect impression.

DB<1> $x= 100 DB<2> Dump $x SV = IV(0x2f10ee0) at 0x2f10ee4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 100 DB<3> $y = "$x" DB<4> Dump $x SV = PVIV(0x424424) at 0x2f10ee4 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 100 # ^^^ ^^^^ These are important PV = 0x2eeda6c "100"\0 CUR = 3 LEN = 4 DB<5>

$sv->PV() is not returning a value because your scalar isn't marked as having a valid PV value (no POK nor pPOK flags set). I don't know what $sv->PV() actually translates to in C code.

It appears that the scalar had previously been upgraded to type PVIV and Perl doesn't waste resources to downgrade it to type IV when sv_setiv() marks the IV as the only value currently in sync with the SV's value. Perl doesn't even waste time free()ing the PV's buffer or putting a '\0' character at the front of it.

You don't show enough code for me to be able to determine why the "100" string was already sitting cached (it appears) in that SV. You might want to Dump($r) in between each of your steps to gain better insights.

If you want a PV to be cached in the SV, then it looks like $sv->PV() doesn't do that work so you should use the scalar as a string before that.

- tye        


In reply to Re: Confusion over B::PV (POK) by tye
in thread Confusion over B::PV by mje

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.