pIOK
is how Devel::Peek
represents the bit corresponding to bit mask SVp_IOK
. The p
indicates a "private" flag, and it forms a pair with "public" flag IOK
(bit mask SVf_IOK
)
The exact meaning of the private flags has changed across perl versions, but in general terms they mean that the IV
(or NV
or PV
) field of the SV
is "inaccurate" in some way
The most common situation where pIOK
is set on its own (pIOK
is always set if IOK
is set) is where a PV
has been converted to a numeric NV
value. The NV
and IV
fields are both populated, but if the IV
value isn't an accurate representation of the number (i.e. it has been truncated) then pIOK
is set but IOK
is cleared
This code shows a way to reach that state. Variable $pi_str
is set to a string value for π and it is converted to a floating-point value by adding 0.0 and storing it into $pi_num
. Devel::Peek
now shows that NOK/pNOK
and POK/pPOK
are set, but only pIOK
while IOK
remains clear. Looking at the IV
value we can see why: it is set to 3, which is the cached value of int $pi_str
in case we need it again, but it is not an accurate representation of the string "3.14159"
in integer form
use strict;
use warnings 'all';
use Devel::Peek 'Dump';
my $pi_str = "3.14159";
my $pi_num = $pi_str + 0.0;
Dump $pi_str;
output
SV = PVNV(0x28fba68) at 0x3f30d30
REFCNT = 1
FLAGS = (NOK,POK,IsCOW,pIOK,pNOK,pPOK)
IV = 3
NV = 3.14159
PV = 0x3fb7ab8 "3.14159"\0
CUR = 7
LEN = 10
COW_REFCNT = 1
Perl v5.16 and before used to use the flag to indicate "magic" variables (such as tied values) because the value in the IV
field could not be used directly. That was changed in v5.18 and later, and magic values now use pIOK
in the same way as any other value
SVp_IOK
will be true andSV_IOK
will be false, will not? – Broadnax