⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perlguts.1

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 1
📖 第 1 页 / 共 5 页
字号:
\&            /* Get the key from an HE structure and also return\&               the length of the key string */\&    SV*    hv_iterval(HV*, HE* entry);\&            /* Return an SV pointer to the value of the HE\&               structure */\&    SV*    hv_iternextsv(HV*, char** key, I32* retlen);\&            /* This convenience routine combines hv_iternext,\&               hv_iterkey, and hv_iterval.  The key and retlen\&               arguments are return values for the key and its\&               length.  The value is returned in the SV* argument */.Ve.PPIf you know the name of a hash variable, you can get a pointer to its \s-1HV\s0by using the following:.PP.Vb 1\&    HV*  get_hv("package::varname", FALSE);.Ve.PPThis returns \s-1NULL\s0 if the variable does not exist..PPThe hash algorithm is defined in the \f(CW\*(C`PERL_HASH(hash, key, klen)\*(C'\fR macro:.PP.Vb 4\&    hash = 0;\&    while (klen\-\-)\&        hash = (hash * 33) + *key++;\&    hash = hash + (hash >> 5);                  /* after 5.6 */.Ve.PPThe last step was added in version 5.6 to improve distribution oflower bits in the resulting hash value..PPSee \*(L"Understanding the Magic of Tied Hashes and Arrays\*(R" for moreinformation on how to use the hash access functions on tied hashes..Sh "Hash \s-1API\s0 Extensions".IX Subsection "Hash API Extensions"Beginning with version 5.004, the following functions are also supported:.PP.Vb 2\&    HE*     hv_fetch_ent  (HV* tb, SV* key, I32 lval, U32 hash);\&    HE*     hv_store_ent  (HV* tb, SV* key, SV* val, U32 hash);\&\&    bool    hv_exists_ent (HV* tb, SV* key, U32 hash);\&    SV*     hv_delete_ent (HV* tb, SV* key, I32 flags, U32 hash);\&\&    SV*     hv_iterkeysv  (HE* entry);.Ve.PPNote that these functions take \f(CW\*(C`SV*\*(C'\fR keys, which simplifies writingof extension code that deals with hash structures.  These functionsalso allow passing of \f(CW\*(C`SV*\*(C'\fR keys to \f(CW\*(C`tie\*(C'\fR functions without forcingyou to stringify the keys (unlike the previous set of functions)..PPThey also return and accept whole hash entries (\f(CW\*(C`HE*\*(C'\fR), making theiruse more efficient (since the hash number for a particular stringdoesn't have to be recomputed every time).  See perlapi for detaileddescriptions..PPThe following macros must always be used to access the contents of hashentries.  Note that the arguments to these macros must be simplevariables, since they may get evaluated more than once.  Seeperlapi for detailed descriptions of these macros..PP.Vb 6\&    HePV(HE* he, STRLEN len)\&    HeVAL(HE* he)\&    HeHASH(HE* he)\&    HeSVKEY(HE* he)\&    HeSVKEY_force(HE* he)\&    HeSVKEY_set(HE* he, SV* sv).Ve.PPThese two lower level macros are defined, but must only be used whendealing with keys that are not \f(CW\*(C`SV*\*(C'\fRs:.PP.Vb 2\&    HeKEY(HE* he)\&    HeKLEN(HE* he).Ve.PPNote that both \f(CW\*(C`hv_store\*(C'\fR and \f(CW\*(C`hv_store_ent\*(C'\fR do not increment thereference count of the stored \f(CW\*(C`val\*(C'\fR, which is the caller's responsibility.If these functions return a \s-1NULL\s0 value, the caller will usually have todecrement the reference count of \f(CW\*(C`val\*(C'\fR to avoid a memory leak..Sh "AVs, HVs and undefined values".IX Subsection "AVs, HVs and undefined values"Sometimes you have to store undefined values in AVs or HVs. Althoughthis may be a rare case, it can be tricky. That's because you'reused to using \f(CW&PL_sv_undef\fR if you need an undefined \s-1SV\s0..PPFor example, intuition tells you that this \s-1XS\s0 code:.PP.Vb 2\&    AV *av = newAV();\&    av_store( av, 0, &PL_sv_undef );.Ve.PPis equivalent to this Perl code:.PP.Vb 2\&    my @av;\&    $av[0] = undef;.Ve.PPUnfortunately, this isn't true. AVs use \f(CW&PL_sv_undef\fR as a markerfor indicating that an array element has not yet been initialized.Thus, \f(CW\*(C`exists $av[0]\*(C'\fR would be true for the above Perl code, butfalse for the array generated by the \s-1XS\s0 code..PPOther problems can occur when storing \f(CW&PL_sv_undef\fR in HVs:.PP.Vb 1\&    hv_store( hv, "key", 3, &PL_sv_undef, 0 );.Ve.PPThis will indeed make the value \f(CW\*(C`undef\*(C'\fR, but if you try to modifythe value of \f(CW\*(C`key\*(C'\fR, you'll get the following error:.PP.Vb 1\&    Modification of non\-creatable hash value attempted.Ve.PPIn perl 5.8.0, \f(CW&PL_sv_undef\fR was also used to mark placeholdersin restricted hashes. This caused such hash entries not to appearwhen iterating over the hash or when checking for the keyswith the \f(CW\*(C`hv_exists\*(C'\fR function..PPYou can run into similar problems when you store \f(CW&PL_sv_true\fR or\&\f(CW&PL_sv_false\fR into AVs or HVs. Trying to modify such elementswill give you the following error:.PP.Vb 1\&    Modification of a read\-only value attempted.Ve.PPTo make a long story short, you can use the special variables\&\f(CW&PL_sv_undef\fR, \f(CW&PL_sv_true\fR and \f(CW&PL_sv_false\fR with AVs andHVs, but you have to make sure you know what you're doing..PPGenerally, if you want to store an undefined value in an \s-1AV\s0or \s-1HV\s0, you should not use \f(CW&PL_sv_undef\fR, but rather create anew undefined value using the \f(CW\*(C`newSV\*(C'\fR function, for example:.PP.Vb 2\&    av_store( av, 42, newSV(0) );\&    hv_store( hv, "foo", 3, newSV(0), 0 );.Ve.Sh "References".IX Subsection "References"References are a special type of scalar that point to other data types(including references)..PPTo create a reference, use either of the following functions:.PP.Vb 2\&    SV* newRV_inc((SV*) thing);\&    SV* newRV_noinc((SV*) thing);.Ve.PPThe \f(CW\*(C`thing\*(C'\fR argument can be any of an \f(CW\*(C`SV*\*(C'\fR, \f(CW\*(C`AV*\*(C'\fR, or \f(CW\*(C`HV*\*(C'\fR.  Thefunctions are identical except that \f(CW\*(C`newRV_inc\*(C'\fR increments the referencecount of the \f(CW\*(C`thing\*(C'\fR, while \f(CW\*(C`newRV_noinc\*(C'\fR does not.  For historicalreasons, \f(CW\*(C`newRV\*(C'\fR is a synonym for \f(CW\*(C`newRV_inc\*(C'\fR..PPOnce you have a reference, you can use the following macro to dereferencethe reference:.PP.Vb 1\&    SvRV(SV*).Ve.PPthen call the appropriate routines, casting the returned \f(CW\*(C`SV*\*(C'\fR to either an\&\f(CW\*(C`AV*\*(C'\fR or \f(CW\*(C`HV*\*(C'\fR, if required..PPTo determine if an \s-1SV\s0 is a reference, you can use the following macro:.PP.Vb 1\&    SvROK(SV*).Ve.PPTo discover what type of value the reference refers to, use the followingmacro and then check the return value..PP.Vb 1\&    SvTYPE(SvRV(SV*)).Ve.PPThe most useful types that will be returned are:.PP.Vb 9\&    SVt_IV    Scalar\&    SVt_NV    Scalar\&    SVt_PV    Scalar\&    SVt_RV    Scalar\&    SVt_PVAV  Array\&    SVt_PVHV  Hash\&    SVt_PVCV  Code\&    SVt_PVGV  Glob (possible a file handle)\&    SVt_PVMG  Blessed or Magical Scalar\&\&    See the sv.h header file for more details..Ve.Sh "Blessed References and Class Objects".IX Subsection "Blessed References and Class Objects"References are also used to support object-oriented programming.  In perl's\&\s-1OO\s0 lexicon, an object is simply a reference that has been blessed into apackage (or class).  Once blessed, the programmer may now use the referenceto access the various methods in the class..PPA reference can be blessed into a package with the following function:.PP.Vb 1\&    SV* sv_bless(SV* sv, HV* stash);.Ve.PPThe \f(CW\*(C`sv\*(C'\fR argument must be a reference value.  The \f(CW\*(C`stash\*(C'\fR argumentspecifies which class the reference will belong to.  See\&\*(L"Stashes and Globs\*(R" for information on converting class names into stashes..PP/* Still under construction */.PPUpgrades rv to reference if not already one.  Creates new \s-1SV\s0 for rv topoint to.  If \f(CW\*(C`classname\*(C'\fR is non-null, the \s-1SV\s0 is blessed into the specifiedclass.  \s-1SV\s0 is returned..PP.Vb 1\&        SV* newSVrv(SV* rv, const char* classname);.Ve.PPCopies integer, unsigned integer or double into an \s-1SV\s0 whose reference is \f(CW\*(C`rv\*(C'\fR.  \s-1SV\s0 is blessedif \f(CW\*(C`classname\*(C'\fR is non-null..PP.Vb 3\&        SV* sv_setref_iv(SV* rv, const char* classname, IV iv);\&        SV* sv_setref_uv(SV* rv, const char* classname, UV uv);\&        SV* sv_setref_nv(SV* rv, const char* classname, NV iv);.Ve.PPCopies the pointer value (\fIthe address, not the string!\fR) into an \s-1SV\s0 whosereference is rv.  \s-1SV\s0 is blessed if \f(CW\*(C`classname\*(C'\fR is non-null..PP.Vb 1\&        SV* sv_setref_pv(SV* rv, const char* classname, PV iv);.Ve.PPCopies string into an \s-1SV\s0 whose reference is \f(CW\*(C`rv\*(C'\fR.  Set length to 0 to letPerl calculate the string length.  \s-1SV\s0 is blessed if \f(CW\*(C`classname\*(C'\fR is non-null..PP.Vb 1\&        SV* sv_setref_pvn(SV* rv, const char* classname, PV iv, STRLEN length);.Ve.PPTests whether the \s-1SV\s0 is blessed into the specified class.  It does notcheck inheritance relationships..PP.Vb 1\&        int  sv_isa(SV* sv, const char* name);.Ve.PPTests whether the \s-1SV\s0 is a reference to a blessed object..PP.Vb 1\&        int  sv_isobject(SV* sv);.Ve.PPTests whether the \s-1SV\s0 is derived from the specified class. \s-1SV\s0 can be eithera reference to a blessed object or a string containing a class name. Thisis the function implementing the \f(CW\*(C`UNIVERSAL::isa\*(C'\fR functionality..PP.Vb 1\&        bool sv_derived_from(SV* sv, const char* name);.Ve.PPTo check if you've got an object derived from a specific class you haveto write:.PP.Vb 1\&        if (sv_isobject(sv) && sv_derived_from(sv, class)) { ... }.Ve.Sh "Creating New Variables".IX Subsection "Creating New Variables"To create a new Perl variable with an undef value which can be accessed fromyour Perl script, use the following routines, depending on the variable type..PP.Vb 3\&    SV*  get_sv("package::varname", TRUE);\&    AV*  get_av("package::varname", TRUE);\&    HV*  get_hv("package::varname", TRUE);.Ve.PPNotice the use of \s-1TRUE\s0 as the second parameter.  The new variable can nowbe set, using the routines appropriate to the data type..PPThere are additional macros whose values may be bitwise \s-1OR\s0'ed with the\&\f(CW\*(C`TRUE\*(C'\fR argument to enable certain extra features.  Those bits are:.IP "\s-1GV_ADDMULTI\s0" 4.IX Item "GV_ADDMULTI"Marks the variable as multiply defined, thus preventing the:.Sp.Vb 1\&  Name <varname> used only once: possible typo.Ve.Spwarning..IP "\s-1GV_ADDWARN\s0" 4.IX Item "GV_ADDWARN"Issues the warning:.Sp.Vb 1

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -