Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Where to find info on low level perl internals names?

by ikegami (Pope)
on Oct 25, 2011 at 19:38 UTC ( #933683=note: print w/ replies, xml ) Need Help??


in reply to Where to find info on low level perl internals names?

Your use of "is" is incorrect when talking about scalar types. An IV is not necessarily an integer.

$ perl -MB -E'$_=123; $_=undef; say B::class B::svref_2object \$_' IV

SV is the base "class" for all Perl variables (not just scalars), but yeah, the "S" stands for "scalar".

Here goes:

B class nameActual SV typeDescriptionExample
SPECIALNULLCan hold undefperl -MB -E'say B::class B::svref_2object \undef'
PVPVCan hold undef, a string of 8 bit chars or a string of 32/64 bit charsperl -MB -E'say B::class B::svref_2object \"a"'
IVIVCan hold undef, a reference, a signed int or an unsigned integerperl -MB -E'say B::class B::svref_2object \123'
NVNVCan hold undef or a floating point numberperl -MB -E'say B::class B::svref_2object \1.3'
PVIVPVIVCan hold undef, a reference, a signed int, an unsigned integer, a string of 8 bit chars and/or a string of 32/64 bit charsperl -MB -E'$_=123; "".$_; say B::class B::svref_2object \$_'
PVNVPVNVCan hold undef, a reference, a signed int, an unsigned integer, a floating point number, a string of 8 bit chars and/or a string of 32/64 bit charsperl -MB -E'$_=1.3; "".$_; say B::class B::svref_2object \$_'
PVMGPVMGA PVNV that supports magicperl -MB -E'say B::class B::svref_2object \$|'
PVLVPVLVA PVMG with extra fields, used for lvaluesperl -MB -E'say B::class B::svref_2object \substr("",0)'
GVPVGVA globperl -MB -E'say B::class B::svref_2object \*FOO'
AVPVAVAn arrayperl -MB -E'say B::class B::svref_2object []'
HVPVHVA hashperl -MB -E'say B::class B::svref_2object {}'
CVPVCVA subperl -MB -E'say B::class B::svref_2object sub{}'
FMPVFMA format
use B; use feature qw( say ); format X = Foo . say B::class B::svref_2object *X{FORMAT};
IOPVIOCan hold a file handle or a directory handleperl -MB -E'say B::class B::svref_2object *STDOUT{IO}'
REGEXPREGEXPA regexp objectperl -MB -E'say B::class B::svref_2object qr//'

The "P" in "PV" is for "pointer".

Where "and/or" is used, all combinations are possible, with the following exceptions:

  • An undefined scalar is one that contains nothing at all, so a scalar cannot contain both undef and something else.
  • A scalar cannot contain two or more of the following at a time: a reference, a signed integer and an unsigned integer.
  • A scalar cannot contain both of the following at a time: a string of 8 bit chars and a string of 32/64 bit chars

While it is technically possible for some scalars to contain both a reference and something else, Perl doesn't create these, and I don't know how safe it is.


Comment on Re: Where to find info on low level perl internals names?
Select or Download Code
Re^2: Where to find info on low level perl internals names? (parent updated)
by ikegami (Pope) on Oct 25, 2011 at 20:27 UTC

    I revamped the table in the parent.

    • Cleared up confusion that came from "IV" and the like having somewhat different meanings in different contexts.
    • Cleared up confusion due to difference between B class names and the actual SV type name
    • Since the question was about B class names, the examples were changed from using Devel::Peek to using B.
    • Added many missing class names.
Re^2: Where to find info on low level perl internals names?
by patcat88 (Deacon) on Oct 26, 2011 at 03:00 UTC
    A scalar cannot contain both of the following at a time: a string of 8 bit chars and a string of 32/64 bit chars

    32bit chars? 64bit chars? UTF 16? UTF 32? UTF 64 jkjk?

      32bit chars? 64bit chars?

      32 on 32 bit builds. 64 on 64 bit builds. The format actually allows for 72 bit numbers, but Perl doesn't provide a means of storing and fetching values that large.

      UTF 16? UTF 32? UTF 64

      Are you asking about the format? It's a variable width format based on UTF-8 confusingly called utf8, but it has nothing to do with Unicode. For starters, the highest possible Unicode character is only 0x10FFFF, far less than what utf8 allows. Unicode has a bunch of reserved and private use and whatnot code points, but not these strings. Unicode imposes certain semantics, but not these strings.

Re^2: Where to find info on low level perl internals names?
by Tux (Monsignor) on Oct 26, 2011 at 06:34 UTC

    Note that there is actually TWO different types of content for IO that differ only slightly in internal storage, but a lot in behavior. There are open files (including sockets and scalar-IO) and open directories. The difference is invisible from the outside:

    $ perl -MDP -we'open DH,$0;DDump*DH' SV = PVGV(0x11d7dc0) at 0x76a5e0 REFCNT = 3 FLAGS = (MULTI) NAME = "DH" NAMELEN = 2 GvSTASH = 0x74af48 "main" GP = 0x771bc0 SV = 0x0 REFCNT = 1 IO = 0x76a5f8 FORM = 0x0 AV = 0x0 HV = 0x0 CV = 0x0 CVGEN = 0x0 LINE = 1 FILE = "-e" FLAGS = 0x2 EGV = 0x76a5e0 "DH" $ perl -MDP -we'opendir DH,".";DDump*DH' SV = PVGV(0x11d7e00) at 0x76a5f0 REFCNT = 3 FLAGS = (MULTI) NAME = "DH" NAMELEN = 2 GvSTASH = 0x74af48 "main" GP = 0x771b30 SV = 0x0 REFCNT = 1 IO = 0x76a620 FORM = 0x0 AV = 0x0 HV = 0x0 CV = 0x0 CVGEN = 0x0 LINE = 1 FILE = "-e" FLAGS = 0x2 EGV = 0x76a5f0 "DH"

    Enjoy, Have FUN! H.Merijn

      In both case, we have scalars of the same type (PVIO). But just like an IV can hold more than one kind of data, PVIO can contain one of two types of handles. I'll clarify that in my table.

      By the way, you didn't show the difference, so here goes:

      $ perl -MDevel::Peek -we'open FH,$^X; Dump *FH{IO}' SV = IV(0x7564a8) at 0x7564b0 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x7693f0 SV = PVIO(0x76ccb8) at 0x7693f0 REFCNT = 2 FLAGS = (OBJECT) STASH = 0x768b68 "IO::File" IFP = 0x763b30 OFP = 0x0 DIRP = 0x0 LINES = 0 PAGE = 0 PAGE_LEN = 60 LINES_LEFT = 0 TOP_GV = 0x0 FMT_GV = 0x0 BOTTOM_GV = 0x0 TYPE = '<' FLAGS = 0x0 $ perl -MDevel::Peek -we'opendir DH,"."; Dump *DH{IO}' SV = IV(0x759d18) at 0x759d20 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x76cc78 SV = PVIO(0x770528) at 0x76cc78 REFCNT = 2 FLAGS = (OBJECT) STASH = 0x76c3d8 "IO::File" IFP = 0x0 OFP = 0x0 DIRP = 0x7a7330 LINES = 0 PAGE = 0 PAGE_LEN = 60 LINES_LEFT = 0 TOP_GV = 0x0 FMT_GV = 0x0 BOTTOM_GV = 0x0 TYPE = '\0' FLAGS = 0x0

        You're example shows the difference. You can only get to that when *explicitly* looking at the IO glob part. I wanted to stress that when not doing so, you cannot see it. Together this is valuable information :)


        Enjoy, Have FUN! H.Merijn

      Thanks again!

      I'm kinda laughing at myself, and you might enjoy the laugh as well, so I might as well share... I spent a few minutes staring at the output of those two commands you posted trying to spot "the difference." ;)

      (sigh) sometimes I make myself wonder.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://933683]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2014-11-25 00:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (148 votes), past polls