perlapi.html

来自「perl教程」· HTML 代码 · 共 2,025 行 · 第 1/5 页

HTML
2,025 行
字号
        SV*     HeVAL(HE* he)</pre>
</dd>
</li>
<dt><strong><a name="item_hvname">HvNAME</a></strong>

<dd>
<p>Returns the package name of a stash, or NULL if <code>stash</code> isn't a stash.
See <a href="#item_svstash"><code>SvSTASH</code></a>, <a href="#item_cvstash"><code>CvSTASH</code></a>.</p>
</dd>
<dd>
<pre>
        char*   HvNAME(HV* stash)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_clear">hv_clear</a></strong>

<dd>
<p>Clears a hash, making it empty.</p>
</dd>
<dd>
<pre>
        void    hv_clear(HV* tb)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_clear_placeholders">hv_clear_placeholders</a></strong>

<dd>
<p>Clears any placeholders from a hash.  If a restricted hash has any of its keys
marked as readonly and the key is subsequently deleted, the key is not actually
deleted but is marked by assigning it a value of &amp;PL_sv_placeholder.  This tags
it so it will be ignored by future operations such as iterating over the hash,
but will still allow the hash to have a value reassigned to the key at some
future point.  This function clears any such placeholder keys from the hash.
See Hash::Util::lock_keys() for an example of its use.</p>
</dd>
<dd>
<pre>
        void    hv_clear_placeholders(HV* hb)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_delete">hv_delete</a></strong>

<dd>
<p>Deletes a key/value pair in the hash.  The value SV is removed from the
hash and returned to the caller.  The <code>klen</code> is the length of the key.
The <a href="../../lib/Pod/perlfunc.html#item_flags"><code>flags</code></a> value will normally be zero; if set to G_DISCARD then NULL
will be returned.</p>
</dd>
<dd>
<pre>
        SV*     hv_delete(HV* tb, const char* key, I32 klen, I32 flags)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_delete_ent">hv_delete_ent</a></strong>

<dd>
<p>Deletes a key/value pair in the hash.  The value SV is removed from the
hash and returned to the caller.  The <a href="../../lib/Pod/perlfunc.html#item_flags"><code>flags</code></a> value will normally be zero;
if set to G_DISCARD then NULL will be returned.  <code>hash</code> can be a valid
precomputed hash value, or 0 to ask for it to be computed.</p>
</dd>
<dd>
<pre>
        SV*     hv_delete_ent(HV* tb, SV* key, I32 flags, U32 hash)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_exists">hv_exists</a></strong>

<dd>
<p>Returns a boolean indicating whether the specified hash key exists.  The
<code>klen</code> is the length of the key.</p>
</dd>
<dd>
<pre>
        bool    hv_exists(HV* tb, const char* key, I32 klen)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_exists_ent">hv_exists_ent</a></strong>

<dd>
<p>Returns a boolean indicating whether the specified hash key exists. <code>hash</code>
can be a valid precomputed hash value, or 0 to ask for it to be
computed.</p>
</dd>
<dd>
<pre>
        bool    hv_exists_ent(HV* tb, SV* key, U32 hash)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_fetch">hv_fetch</a></strong>

<dd>
<p>Returns the SV which corresponds to the specified key in the hash.  The
<code>klen</code> is the length of the key.  If <code>lval</code> is set then the fetch will be
part of a store.  Check that the return value is non-null before
dereferencing it to an <code>SV*</code>.</p>
</dd>
<dd>
<p>See <a href="../../lib/Pod/perlguts.html#understanding_the_magic_of_tied_hashes_and_arrays">Understanding the Magic of Tied Hashes and Arrays in the perlguts manpage</a> for more
information on how to use this function on tied hashes.</p>
</dd>
<dd>
<pre>
        SV**    hv_fetch(HV* tb, const char* key, I32 klen, I32 lval)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_fetch_ent">hv_fetch_ent</a></strong>

<dd>
<p>Returns the hash entry which corresponds to the specified key in the hash.
<code>hash</code> must be a valid precomputed hash number for the given <code>key</code>, or 0
if you want the function to compute it.  IF <code>lval</code> is set then the fetch
will be part of a store.  Make sure the return value is non-null before
accessing it.  The return value when <code>tb</code> is a tied hash is a pointer to a
static location, so be sure to make a copy of the structure if you need to
store it somewhere.</p>
</dd>
<dd>
<p>See <a href="../../lib/Pod/perlguts.html#understanding_the_magic_of_tied_hashes_and_arrays">Understanding the Magic of Tied Hashes and Arrays in the perlguts manpage</a> for more
information on how to use this function on tied hashes.</p>
</dd>
<dd>
<pre>
        HE*     hv_fetch_ent(HV* tb, SV* key, I32 lval, U32 hash)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_iterinit">hv_iterinit</a></strong>

<dd>
<p>Prepares a starting point to traverse a hash table.  Returns the number of
keys in the hash (i.e. the same as <code>HvKEYS(tb)</code>).  The return value is
currently only meaningful for hashes without tie magic.</p>
</dd>
<dd>
<p>NOTE: Before version 5.004_65, <a href="#item_hv_iterinit"><code>hv_iterinit</code></a> used to return the number of
hash buckets that happen to be in use.  If you still need that esoteric
value, you can get it through the macro <code>HvFILL(tb)</code>.</p>
</dd>
<dd>
<pre>
        I32     hv_iterinit(HV* tb)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_iterkey">hv_iterkey</a></strong>

<dd>
<p>Returns the key from the current position of the hash iterator.  See
<a href="#item_hv_iterinit"><code>hv_iterinit</code></a>.</p>
</dd>
<dd>
<pre>
        char*   hv_iterkey(HE* entry, I32* retlen)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_iterkeysv">hv_iterkeysv</a></strong>

<dd>
<p>Returns the key as an <code>SV*</code> from the current position of the hash
iterator.  The return value will always be a mortal copy of the key.  Also
see <a href="#item_hv_iterinit"><code>hv_iterinit</code></a>.</p>
</dd>
<dd>
<pre>
        SV*     hv_iterkeysv(HE* entry)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_iternext">hv_iternext</a></strong>

<dd>
<p>Returns entries from a hash iterator.  See <a href="#item_hv_iterinit"><code>hv_iterinit</code></a>.</p>
</dd>
<dd>
<p>You may call <a href="#item_hv_delete"><code>hv_delete</code></a> or <a href="#item_hv_delete_ent"><code>hv_delete_ent</code></a> on the hash entry that the
iterator currently points to, without losing your place or invalidating your
iterator.  Note that in this case the current entry is deleted from the hash
with your iterator holding the last reference to it.  Your iterator is flagged
to free the entry on the next call to <a href="#item_hv_iternext"><code>hv_iternext</code></a>, so you must not discard
your iterator immediately else the entry will leak - call <a href="#item_hv_iternext"><code>hv_iternext</code></a> to
trigger the resource deallocation.</p>
</dd>
<dd>
<pre>
        HE*     hv_iternext(HV* tb)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_iternextsv">hv_iternextsv</a></strong>

<dd>
<p>Performs an <a href="#item_hv_iternext"><code>hv_iternext</code></a>, <a href="#item_hv_iterkey"><code>hv_iterkey</code></a>, and <a href="#item_hv_iterval"><code>hv_iterval</code></a> in one
operation.</p>
</dd>
<dd>
<pre>
        SV*     hv_iternextsv(HV* hv, char** key, I32* retlen)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_iternext_flags">hv_iternext_flags</a></strong>

<dd>
<p>Returns entries from a hash iterator.  See <a href="#item_hv_iterinit"><code>hv_iterinit</code></a> and <a href="#item_hv_iternext"><code>hv_iternext</code></a>.
The <a href="../../lib/Pod/perlfunc.html#item_flags"><code>flags</code></a> value will normally be zero; if HV_ITERNEXT_WANTPLACEHOLDERS is
set the placeholders keys (for restricted hashes) will be returned in addition
to normal keys. By default placeholders are automatically skipped over.
Currently a placeholder is implemented with a value that is
<code>&amp;Perl_sv_placeholder</code>. Note that the implementation of placeholders and
restricted hashes may change, and the implementation currently is
insufficiently abstracted for any change to be tidy.</p>
</dd>
<dd>
<p>NOTE: this function is experimental and may change or be
removed without notice.</p>
</dd>
<dd>
<pre>
        HE*     hv_iternext_flags(HV* tb, I32 flags)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_iterval">hv_iterval</a></strong>

<dd>
<p>Returns the value from the current position of the hash iterator.  See
<a href="#item_hv_iterkey"><code>hv_iterkey</code></a>.</p>
</dd>
<dd>
<pre>
        SV*     hv_iterval(HV* tb, HE* entry)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_magic">hv_magic</a></strong>

<dd>
<p>Adds magic to a hash.  See <a href="#item_sv_magic"><code>sv_magic</code></a>.</p>
</dd>
<dd>
<pre>
        void    hv_magic(HV* hv, GV* gv, int how)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_scalar">hv_scalar</a></strong>

<dd>
<p>Evaluates the hash in scalar context and returns the result. Handles magic when the hash is tied.</p>
</dd>
<dd>
<pre>
        SV*     hv_scalar(HV* hv)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_store">hv_store</a></strong>

<dd>
<p>Stores an SV in a hash.  The hash key is specified as <code>key</code> and <code>klen</code> is
the length of the key.  The <code>hash</code> parameter is the precomputed hash
value; if it is zero then Perl will compute it.  The return value will be
NULL if the operation failed or if the value did not need to be actually
stored within the hash (as in the case of tied hashes).  Otherwise it can
be dereferenced to get the original <code>SV*</code>.  Note that the caller is
responsible for suitably incrementing the reference count of <code>val</code> before
the call, and decrementing it if the function returned NULL.  Effectively
a successful hv_store takes ownership of one reference to <code>val</code>.  This is
usually what you want; a newly created SV has a reference count of one, so
if all your code does is create SVs then store them in a hash, hv_store
will own the only reference to the new SV, and your code doesn't need to do
anything further to tidy up.  hv_store is not implemented as a call to
hv_store_ent, and does not create a temporary SV for the key, so if your
key data is not already in SV form then use hv_store in preference to
hv_store_ent.</p>
</dd>
<dd>
<p>See <a href="../../lib/Pod/perlguts.html#understanding_the_magic_of_tied_hashes_and_arrays">Understanding the Magic of Tied Hashes and Arrays in the perlguts manpage</a> for more
information on how to use this function on tied hashes.</p>
</dd>
<dd>
<pre>
        SV**    hv_store(HV* tb, const char* key, I32 klen, SV* val, U32 hash)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_store_ent">hv_store_ent</a></strong>

<dd>
<p>Stores <code>val</code> in a hash.  The hash key is specified as <code>key</code>.  The <code>hash</code>
parameter is the precomputed hash value; if it is zero then Perl will
compute it.  The return value is the new hash entry so created.  It will be
NULL if the operation failed or if the value did not need to be actually
stored within the hash (as in the case of tied hashes).  Otherwise the
contents of the return value can be accessed using the <code>He?</code> macros
described here.  Note that the caller is responsible for suitably
incrementing the reference count of <code>val</code> before the call, and
decrementing it if the function returned NULL.  Effectively a successful
hv_store_ent takes ownership of one reference to <code>val</code>.  This is
usually what you want; a newly created SV has a reference count of one, so
if all your code does is create SVs then store them in a hash, hv_store
will own the only reference to the new SV, and your code doesn't need to do
anything further to tidy up.  Note that hv_store_ent only reads the <code>key</code>;
unlike <code>val</code> it does not take ownership of it, so maintaining the correct
reference count on <code>key</code> is entirely the caller's responsibility.  hv_store
is not implemented as a call to hv_store_ent, and does not create a temporary
SV for the key, so if your key data is not already in SV form then use
hv_store in preference to hv_store_ent.</p>
</dd>
<dd>
<p>See <a href="../../lib/Pod/perlguts.html#understanding_the_magic_of_tied_hashes_and_arrays">Understanding the Magic of Tied Hashes and Arrays in the perlguts manpage</a> for more
information on how to use this function on tied hashes.</p>
</dd>
<dd>
<pre>
        HE*     hv_store_ent(HV* tb, SV* key, SV* val, U32 hash)</pre>
</dd>
</li>
<dt><strong><a name="item_hv_undef">hv_undef</a></strong>

<dd>
<p>Undefines the hash.</p>
</dd>
<dd>
<pre>
        void    hv_undef(HV* tb)</pre>
</dd>
</li>
<dt><strong><a name="item_newhv">newHV</a></strong>

<dd>
<p>Creates a new HV.  The reference count is set to 1.</p>
</dd>
<dd>
<pre>
        HV*     newHV()</pre>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="magical_functions">Magical Functions</a></h1>
<dl>
<dt><strong><a name="item_mg_clear">mg_clear</a></strong>

<dd>
<p>Clear something magical that the SV represents.  See <a href="#item_sv_magic"><code>sv_magic</code></a>.</p>
</dd>
<dd>
<pre>
        int     mg_clear(SV* sv)</pre>
</dd>
</li>
<dt><strong><a name="item_mg_copy">mg_copy</a></strong>

<dd>
<p>Copies the magic from one SV to another.  See <a href="#item_sv_magic"><code>sv_magic</code></a>.</p>
</dd>
<dd>
<pre>
        int     mg_copy(SV* sv, SV* nsv, const char* key, I32 klen)</pre>
</dd>
</li>
<dt><strong><a name="item_mg_find">mg_find</a></strong>

<dd>
<p>Finds the magic pointer for type matching the SV.  See <a href="#item_sv_magic"><code>sv_magic</code></a>.</p>
</dd>
<dd>
<pre>
        MAGIC*  mg_find(SV* sv, int type)</pre>
</dd>
</li>
<dt><strong><a name="item_mg_free">mg_free</a></strong>

<dd>
<p>Free any magic storage used by the SV.  See <a href="#item_sv_magic"><code>sv_magic</code></a>.</p>
</dd>
<dd>
<pre>
        int     mg_free(SV* sv)</pre>
</dd>
</li>
<dt><strong><a name="item_mg_get">mg_get</a></strong>

<dd>
<p>Do magic after a value is retrieved from the SV.  See <a href="#item_sv_magic"><code>sv_magic</code></a>.</p>
</dd>
<dd>
<pre>
        int     mg_get(SV* sv)</pre>
</dd>
</li>
<dt><strong><a name="item_mg_length">mg_length</a></strong>

<dd>
<p>Report on the SV's length.  See <a href="#item_sv_magic"><code>sv_magic</code></a>.</p>
</dd>
<dd>
<pre>
        U32     mg_length(SV* sv)</pre>
</dd>
</li>
<dt><strong><a name="item_mg_magical">mg_magical</a></strong>

<dd>
<p>Turns on the magical status of an SV.  See <a href="#item_sv_magic"><code>sv_magic</code></a>.</p>
</dd>
<dd>
<pre>
        void    mg_magical(SV* sv)</pre>
</dd>
</li>

⌨️ 快捷键说明

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