Perl 内部结构详解 -- PerlGuts Illustrated (5 GV & Stash)
GVGV "Global Value" 或者“符号表”,存储着变量或者函数的指针GP,由GP中slot 相关的指示来决定是否存在对应这个变量相应的类型。如图所示:GP可以在多个GV中共享,试运行下例查看结果。
示例察看main 空间的内容,*:: 等同于*main::D:\Tmp>perl -MDevel::Peek -e "Dump \%Devel::,1000"SV = RV(0x3a90e0) at 0x3a90d4 REFCNT = 1 FLAGS = (TEMP,ROK) RV = 0x285a9dc SV = PVHV(0x3ae57c) at 0x285a9dc REFCNT = 2 FLAGS = (OOK,SHAREKEYS) ARRAY = 0x2865534 (0:7, 1:1) hash quality = 100.0% KEYS = 1 FILL = 1 MAX = 7 RITER = -1 EITER = 0x0 NAME = "Devel" BACKREFS = 0x285a9fc SV = PVAV(0x3aa32c) at 0x285a9fc REFCNT = 2 FLAGS = () ARRAY = 0x286561c FILL = 0 MAX = 3 ARYLEN = 0x0 FLAGS = () Elt No. 0 SV = PVGV(0x285c334) at 0x285a9ec REFCNT = 1 FLAGS = (MULTI) NAME = "Peek::" NAMELEN = 6 GvSTASH = 0x285a9dc"Devel" GP = 0x28655dc SV = 0x0 REFCNT = 1 IO = 0x0 FORM = 0x0 AV = 0x0 HV = 0x285aa0c CV = 0x0 CVGEN = 0x0 LINE = 4 FILE = "D:/Perl/lib/Devel/Peek.pm" FLAGS = 0x2 EGV = 0x285a9ec"Peek::" Elt "Peek::" HASH = 0xf40ca9c SV = PVGV(0x285c334) at 0x285a9ec REFCNT = 1 FLAGS = (MULTI) NAME = "Peek::" NAMELEN = 6 GvSTASH = 0x285a9dc"Devel" GP = 0x28655dc SV = 0x0 REFCNT = 1 IO = 0x0 FORM = 0x0 AV = 0x0 HV = 0x285aa0c CV = 0x0 CVGEN = 0x0 LINE = 4 FILE = "D:/Perl/lib/Devel/Peek.pm" FLAGS = 0x2 EGV = 0x285a9ec"Peek::"
希望通过这一节都能对Perl的整体有一个了解,相信其他语言也有类似的概念结构来实现命名空间的引入。