美文网首页
Perl 变量 内部实现机制

Perl 变量 内部实现机制

作者: firefive | 来源:发表于2015-01-27 14:09 被阅读0次

    核心模块 Devel::Peek  允许我们以C语言的角度来观察一个perl 标量。

    数组的源代码定义为

    struct xpvav {

    char*  xav_array;  /* pointer to first array element */

    SSize_t xav_fill;  /* Index of last element present */

    SSize_t xav_max;    /* max index for which array has space */

    IV      xof_off;    /* ptr is incremented by offset */

    NV      xnv_nv;    /* numeric value, if any */

    MAGIC*  xmg_magic;  /* magic for scalar array */

    HV*    xmg_stash;  /* class package */

    SV**    xav_alloc;  /* pointer to malloced string */

    SV*    xav_arylen;

    U8      xav_flags;

    };

    试着运行命令查看啊

    C:\Users>perl  -MDevel::Peek -le "@a=(1,2,3); Dump(\@a)"

    SV = IV(0x74bed0) at 0x74bed4

    REFCNT = 1

    FLAGS = (TEMP,ROK)

    RV = 0x26cf97c

    SV = PVAV(0x74cc38) at 0x26cf97c

    REFCNT = 2

    FLAGS = ()

    ARRAY = 0x26bf5dc

    FILL = 2

    MAX = 3

    ARYLEN = 0x0

    FLAGS = (REAL)

    Elt No. 0

    SV = IV(0x74bda0) at 0x74bda4

    REFCNT = 1

    FLAGS = (IOK,pIOK)

    IV = 1

    Elt No. 1

    SV = IV(0x74be70) at 0x74be74

    REFCNT = 1

    FLAGS = (IOK,pIOK)

    IV = 2

    Elt No. 2

    SV = IV(0x74beb0) at 0x74beb4

    REFCNT = 1

    FLAGS = (IOK,pIOK)

    IV = 3

    相关文章

      网友评论

          本文标题:Perl 变量 内部实现机制

          本文链接:https://www.haomeiwen.com/subject/oozitttx.html