perlapi.html
来自「perl教程」· HTML 代码 · 共 2,025 行 · 第 1/5 页
HTML
2,025 行
<dd>
<p>The engine implementing <a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack()</code></a> Perl function.</p>
</dd>
<dd>
<pre>
void packlist(SV *cat, char *pat, char *patend, SV **beglist, SV **endlist)</pre>
</dd>
</li>
<dt><strong><a name="item_pack_cat">pack_cat</a></strong>
<dd>
<p>The engine implementing <a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack()</code></a> Perl function. Note: parameters next_in_list and
flags are not used. This call should not be used; use packlist instead.</p>
</dd>
<dd>
<pre>
void pack_cat(SV *cat, char *pat, char *patend, SV **beglist, SV **endlist, SV ***next_in_list, U32 flags)</pre>
</dd>
</li>
<dt><strong><a name="item_unpackstring">unpackstring</a></strong>
<dd>
<p>The engine implementing <a href="../../lib/Pod/perlfunc.html#item_unpack"><code>unpack()</code></a> Perl function. <a href="#item_unpackstring"><code>unpackstring</code></a> puts the
extracted list items on the stack and returns the number of elements.
Issue <a href="#item_putback"><code>PUTBACK</code></a> before and <a href="#item_spagain"><code>SPAGAIN</code></a> after the call to this function.</p>
</dd>
<dd>
<pre>
I32 unpackstring(char *pat, char *patend, char *s, char *strend, U32 flags)</pre>
</dd>
</li>
<dt><strong><a name="item_unpack_str">unpack_str</a></strong>
<dd>
<p>The engine implementing <a href="../../lib/Pod/perlfunc.html#item_unpack"><code>unpack()</code></a> Perl function. Note: parameters strbeg, new_s
and ocnt are not used. This call should not be used, use unpackstring instead.</p>
</dd>
<dd>
<pre>
I32 unpack_str(char *pat, char *patend, char *s, char *strbeg, char *strend, char **new_s, I32 ocnt, U32 flags)</pre>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="global_variables">Global Variables</a></h1>
<dl>
<dt><strong><a name="item_pl_modglobal">PL_modglobal</a></strong>
<dd>
<p><a href="#item_pl_modglobal"><code>PL_modglobal</code></a> is a general purpose, interpreter global HV for use by
extensions that need to keep information on a per-interpreter basis.
In a pinch, it can also be used as a symbol table for extensions
to share data among each other. It is a good idea to use keys
prefixed by the package name of the extension that owns the data.</p>
</dd>
<dd>
<pre>
HV* PL_modglobal</pre>
</dd>
</li>
<dt><strong><a name="item_pl_na">PL_na</a></strong>
<dd>
<p>A convenience variable which is typically used with <a href="#item_svpv"><code>SvPV</code></a> when one
doesn't care about the length of the string. It is usually more efficient
to either declare a local variable and use that instead or to use the
<a href="#item_svpv_nolen"><code>SvPV_nolen</code></a> macro.</p>
</dd>
<dd>
<pre>
STRLEN PL_na</pre>
</dd>
</li>
<dt><strong><a name="item_pl_sv_no">PL_sv_no</a></strong>
<dd>
<p>This is the <code>false</code> SV. See <a href="#item_pl_sv_yes"><code>PL_sv_yes</code></a>. Always refer to this as
<code>&PL_sv_no</code>.</p>
</dd>
<dd>
<pre>
SV PL_sv_no</pre>
</dd>
</li>
<dt><strong><a name="item_pl_sv_undef">PL_sv_undef</a></strong>
<dd>
<p>This is the <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> SV. Always refer to this as <code>&PL_sv_undef</code>.</p>
</dd>
<dd>
<pre>
SV PL_sv_undef</pre>
</dd>
</li>
<dt><strong><a name="item_pl_sv_yes">PL_sv_yes</a></strong>
<dd>
<p>This is the <code>true</code> SV. See <a href="#item_pl_sv_no"><code>PL_sv_no</code></a>. Always refer to this as
<code>&PL_sv_yes</code>.</p>
</dd>
<dd>
<pre>
SV PL_sv_yes</pre>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="gv_functions">GV Functions</a></h1>
<dl>
<dt><strong><a name="item_gvsv">GvSV</a></strong>
<dd>
<p>Return the SV from the GV.</p>
</dd>
<dd>
<pre>
SV* GvSV(GV* gv)</pre>
</dd>
</li>
<dt><strong><a name="item_gv_fetchmeth">gv_fetchmeth</a></strong>
<dd>
<p>Returns the glob with the given <code>name</code> and a defined subroutine or
<code>NULL</code>. The glob lives in the given <code>stash</code>, or in the stashes
accessible via @ISA and UNIVERSAL::.</p>
</dd>
<dd>
<p>The argument <code>level</code> should be either 0 or -1. If <code>level==0</code>, as a
side-effect creates a glob with the given <code>name</code> in the given <code>stash</code>
which in the case of success contains an alias for the subroutine, and sets
up caching info for this glob. Similarly for all the searched stashes.</p>
</dd>
<dd>
<p>This function grants <code>"SUPER"</code> token as a postfix of the stash name. The
GV returned from <a href="#item_gv_fetchmeth"><code>gv_fetchmeth</code></a> may be a method cache entry, which is not
visible to Perl code. So when calling <a href="#item_call_sv"><code>call_sv</code></a>, you should not use
the GV directly; instead, you should use the method's CV, which can be
obtained from the GV with the <code>GvCV</code> macro.</p>
</dd>
<dd>
<pre>
GV* gv_fetchmeth(HV* stash, const char* name, STRLEN len, I32 level)</pre>
</dd>
</li>
<dt><strong><a name="item_gv_fetchmethod">gv_fetchmethod</a></strong>
<dd>
<p>See <a href="#item_gv_fetchmethod_autoload">gv_fetchmethod_autoload</a>.</p>
</dd>
<dd>
<pre>
GV* gv_fetchmethod(HV* stash, const char* name)</pre>
</dd>
</li>
<dt><strong><a name="item_gv_fetchmethod_autoload">gv_fetchmethod_autoload</a></strong>
<dd>
<p>Returns the glob which contains the subroutine to call to invoke the method
on the <code>stash</code>. In fact in the presence of autoloading this may be the
glob for "AUTOLOAD". In this case the corresponding variable $AUTOLOAD is
already setup.</p>
</dd>
<dd>
<p>The third parameter of <a href="#item_gv_fetchmethod_autoload"><code>gv_fetchmethod_autoload</code></a> determines whether
AUTOLOAD lookup is performed if the given method is not present: non-zero
means yes, look for AUTOLOAD; zero means no, don't look for AUTOLOAD.
Calling <a href="#item_gv_fetchmethod"><code>gv_fetchmethod</code></a> is equivalent to calling <a href="#item_gv_fetchmethod_autoload"><code>gv_fetchmethod_autoload</code></a>
with a non-zero <code>autoload</code> parameter.</p>
</dd>
<dd>
<p>These functions grant <code>"SUPER"</code> token as a prefix of the method name. Note
that if you want to keep the returned glob for a long time, you need to
check for it being "AUTOLOAD", since at the later time the call may load a
different subroutine due to $AUTOLOAD changing its value. Use the glob
created via a side effect to do this.</p>
</dd>
<dd>
<p>These functions have the same side-effects and as <a href="#item_gv_fetchmeth"><code>gv_fetchmeth</code></a> with
<code>level==0</code>. <code>name</code> should be writable if contains <code>':'</code> or <code>'
''</code>. The warning against passing the GV returned by <a href="#item_gv_fetchmeth"><code>gv_fetchmeth</code></a> to
<a href="#item_call_sv"><code>call_sv</code></a> apply equally to these functions.</p>
</dd>
<dd>
<pre>
GV* gv_fetchmethod_autoload(HV* stash, const char* name, I32 autoload)</pre>
</dd>
</li>
<dt><strong><a name="item_gv_fetchmeth_autoload">gv_fetchmeth_autoload</a></strong>
<dd>
<p>Same as gv_fetchmeth(), but looks for autoloaded subroutines too.
Returns a glob for the subroutine.</p>
</dd>
<dd>
<p>For an autoloaded subroutine without a GV, will create a GV even
if <code>level < 0</code>. For an autoloaded subroutine without a stub, <code>GvCV()</code>
of the result may be zero.</p>
</dd>
<dd>
<pre>
GV* gv_fetchmeth_autoload(HV* stash, const char* name, STRLEN len, I32 level)</pre>
</dd>
</li>
<dt><strong><a name="item_gv_stashpv">gv_stashpv</a></strong>
<dd>
<p>Returns a pointer to the stash for a specified package. <code>name</code> should
be a valid UTF-8 string and must be null-terminated. If <code>create</code> is set
then the package will be created if it does not already exist. If <code>create</code>
is not set and the package does not exist then NULL is returned.</p>
</dd>
<dd>
<pre>
HV* gv_stashpv(const char* name, I32 create)</pre>
</dd>
</li>
<dt><strong><a name="item_gv_stashpvn">gv_stashpvn</a></strong>
<dd>
<p>Returns a pointer to the stash for a specified package. <code>name</code> should
be a valid UTF-8 string. The <code>namelen</code> parameter indicates the length of
the <code>name</code>, in bytes. If <code>create</code> is set then the package will be
created if it does not already exist. If <code>create</code> is not set and the
package does not exist then NULL is returned.</p>
</dd>
<dd>
<pre>
HV* gv_stashpvn(const char* name, U32 namelen, I32 create)</pre>
</dd>
</li>
<dt><strong><a name="item_gv_stashsv">gv_stashsv</a></strong>
<dd>
<p>Returns a pointer to the stash for a specified package, which must be a
valid UTF-8 string. See <a href="#item_gv_stashpv"><code>gv_stashpv</code></a>.</p>
</dd>
<dd>
<pre>
HV* gv_stashsv(SV* sv, I32 create)</pre>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="handy_values">Handy Values</a></h1>
<dl>
<dt><strong><a name="item_nullav">Nullav</a></strong>
<dd>
<p>Null AV pointer.</p>
</dd>
</li>
<dt><strong><a name="item_nullch">Nullch</a></strong>
<dd>
<p>Null character pointer.</p>
</dd>
</li>
<dt><strong><a name="item_nullcv">Nullcv</a></strong>
<dd>
<p>Null CV pointer.</p>
</dd>
</li>
<dt><strong><a name="item_nullhv">Nullhv</a></strong>
<dd>
<p>Null HV pointer.</p>
</dd>
</li>
<dt><strong><a name="item_nullsv">Nullsv</a></strong>
<dd>
<p>Null SV pointer.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="hash_manipulation_functions">Hash Manipulation Functions</a></h1>
<dl>
<dt><strong><a name="item_get_hv">get_hv</a></strong>
<dd>
<p>Returns the HV of the specified Perl hash. If <code>create</code> is set and the
Perl variable does not exist then it will be created. If <code>create</code> is not
set and the variable does not exist then NULL is returned.</p>
</dd>
<dd>
<p>NOTE: the perl_ form of this function is deprecated.</p>
</dd>
<dd>
<pre>
HV* get_hv(const char* name, I32 create)</pre>
</dd>
</li>
<dt><strong><a name="item_hef_svkey">HEf_SVKEY</a></strong>
<dd>
<p>This flag, used in the length slot of hash entries and magic structures,
specifies the structure contains an <code>SV*</code> pointer where a <code>char*</code> pointer
is to be expected. (For information only--not to be used).</p>
</dd>
</li>
<dt><strong><a name="item_hehash">HeHASH</a></strong>
<dd>
<p>Returns the computed hash stored in the hash entry.</p>
</dd>
<dd>
<pre>
U32 HeHASH(HE* he)</pre>
</dd>
</li>
<dt><strong><a name="item_hekey">HeKEY</a></strong>
<dd>
<p>Returns the actual pointer stored in the key slot of the hash entry. The
pointer may be either <code>char*</code> or <code>SV*</code>, depending on the value of
<a href="#item_heklen"><code>HeKLEN()</code></a>. Can be assigned to. The <a href="#item_hepv"><code>HePV()</code></a> or <a href="#item_hesvkey"><code>HeSVKEY()</code></a> macros are
usually preferable for finding the value of a key.</p>
</dd>
<dd>
<pre>
void* HeKEY(HE* he)</pre>
</dd>
</li>
<dt><strong><a name="item_heklen">HeKLEN</a></strong>
<dd>
<p>If this is negative, and amounts to <a href="#item_hef_svkey"><code>HEf_SVKEY</code></a>, it indicates the entry
holds an <code>SV*</code> key. Otherwise, holds the actual length of the key. Can
be assigned to. The <a href="#item_hepv"><code>HePV()</code></a> macro is usually preferable for finding key
lengths.</p>
</dd>
<dd>
<pre>
STRLEN HeKLEN(HE* he)</pre>
</dd>
</li>
<dt><strong><a name="item_hepv">HePV</a></strong>
<dd>
<p>Returns the key slot of the hash entry as a <code>char*</code> value, doing any
necessary dereferencing of possibly <code>SV*</code> keys. The length of the string
is placed in <code>len</code> (this is a macro, so do <em>not</em> use <code>&len</code>). If you do
not care about what the length of the key is, you may use the global
variable <a href="#item_pl_na"><code>PL_na</code></a>, though this is rather less efficient than using a local
variable. Remember though, that hash keys in perl are free to contain
embedded nulls, so using <code>strlen()</code> or similar is not a good way to find
the length of hash keys. This is very similar to the <a href="#item_svpv"><code>SvPV()</code></a> macro
described elsewhere in this document.</p>
</dd>
<dd>
<pre>
char* HePV(HE* he, STRLEN len)</pre>
</dd>
</li>
<dt><strong><a name="item_hesvkey">HeSVKEY</a></strong>
<dd>
<p>Returns the key as an <code>SV*</code>, or <a href="#item_nullsv"><code>Nullsv</code></a> if the hash entry does not
contain an <code>SV*</code> key.</p>
</dd>
<dd>
<pre>
SV* HeSVKEY(HE* he)</pre>
</dd>
</li>
<dt><strong><a name="item_hesvkey_force">HeSVKEY_force</a></strong>
<dd>
<p>Returns the key as an <code>SV*</code>. Will create and return a temporary mortal
<code>SV*</code> if the hash entry contains only a <code>char*</code> key.</p>
</dd>
<dd>
<pre>
SV* HeSVKEY_force(HE* he)</pre>
</dd>
</li>
<dt><strong><a name="item_hesvkey_set">HeSVKEY_set</a></strong>
<dd>
<p>Sets the key to a given <code>SV*</code>, taking care to set the appropriate flags to
indicate the presence of an <code>SV*</code> key, and returns the same
<code>SV*</code>.</p>
</dd>
<dd>
<pre>
SV* HeSVKEY_set(HE* he, SV* sv)</pre>
</dd>
</li>
<dt><strong><a name="item_heval">HeVAL</a></strong>
<dd>
<p>Returns the value slot (type <code>SV*</code>) stored in the hash entry.</p>
</dd>
<dd>
<pre>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?