IV - holds signed int, unsigned int or ref
NV - holds float
PV - holds string
And then there are fields to support magic lvalues and general magic.
Not every field is available at all times. SVs (scalars) have a head which contains a pointer to the body. The body is automatically upgraded when needed (e.g. my $x = 1; $x += 0.1;, tie my $x, ..., etc).
And even if the field is available, not all values are available at all times. Flags indicate which fields are initialised and what they contain.
$ perl -MDevel::Peek -e'
my $x; Dump $x;
$x = 123; Dump $x;
"$x"; Dump $x;
++$x; Dump $x;
$x=undef; Dump $x;
'
Fresh var, no body, no content:
SV = NULL(0x0) at 0x88c6920
REFCNT = 1
FLAGS = (PADMY)
After assigning int,
body upgraded to IV (has field IV), and
IV field contains a number (IOK):
SV = IV(0x88c691c) at 0x88c6920
REFCNT = 1
FLAGS = (PADMY,IOK,pIOK)
IV = 123
After using content as string,
body upgraded to PVIV (has fields IV and PV),
IV field contains a number (IOK), and
PV field contains a string (POK):
SV = PVIV(0x88c56ac) at 0x88c6920
REFCNT = 1
FLAGS = (PADMY,IOK,POK,pIOK,pPOK)
IV = 123
PV = 0x88e7710 "123"\0
CUR = 3
LEN = 4
After using content as a number,
IV field contains a number (IOK), and
PV field isn't being used (!POK):
SV = PVIV(0x88c56ac) at 0x88c6920
REFCNT = 1
FLAGS = (PADMY,IOK,pIOK)
IV = 124
PV = 0x88e7710 "123"\0
CUR = 3
LEN = 4
After clearing the contents,
IV field isn't being used (!IOK), and
PV field isn't being used (!POK):
SV = PVIV(0x88c56ac) at 0x88c6920
REFCNT = 1
FLAGS = (PADMY)
IV = 124
PV = 0x88e7710 "123"\0
CUR = 3
LEN = 4
|