in reply to Confusion over B::PV
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Confusion over B::PV (POK)
by mje (Curate) on May 19, 2012 at 17:59 UTC | |
|
Re^2: Confusion over B::PV (POK)
by mje (Curate) on May 19, 2012 at 17:29 UTC |