hash.html

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

HTML
255
字号
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>Tie::ExtraHash - base class definitions for tied hashes</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>

<body>

<script>writelinks('__top__',2);</script>
<h1><a>Tie::ExtraHash - base class definitions for tied hashes</a></h1>
<p><a name="__index__"></a></p>

<!-- INDEX BEGIN -->

<ul>

	<li><a href="#name">NAME</a></li>
	<li><a href="#synopsis">SYNOPSIS</a></li>
	<li><a href="#description">DESCRIPTION</a></li>
	<li><a href="#inheriting_from_tie__stdhash">Inheriting from <strong>Tie::StdHash</strong></a></li>
	<li><a href="#inheriting_from_tie__extrahash">Inheriting from <strong>Tie::ExtraHash</strong></a></li>
	<li><a href="#scalar__untie_and_destroy"><code>SCALAR</code>, <code>UNTIE</code> and <code>DESTROY</code></a></li>
	<li><a href="#more_information">MORE INFORMATION</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for tied hashes</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
    <span class="keyword">package</span> <span class="variable">NewHash</span><span class="operator">;</span>
    <span class="keyword">require</span> <span class="variable">Tie::Hash</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">@ISA</span> <span class="operator">=</span> <span class="operator">(</span><span class="variable">Tie::Hash</span><span class="operator">);</span>
</pre>
<pre>
    <span class="keyword">sub</span><span class="variable"> DELETE </span><span class="operator">{</span> <span class="operator">...</span> <span class="operator">}</span>          <span class="comment"># Provides needed method</span>
    <span class="keyword">sub</span><span class="variable"> CLEAR </span><span class="operator">{</span> <span class="operator">...</span> <span class="operator">}</span>           <span class="comment"># Overrides inherited method</span>
</pre>
<pre>
    <span class="keyword">package</span> <span class="variable">NewStdHash</span><span class="operator">;</span>
    <span class="keyword">require</span> <span class="variable">Tie::Hash</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">@ISA</span> <span class="operator">=</span> <span class="operator">(</span><span class="variable">Tie::StdHash</span><span class="operator">);</span>
</pre>
<pre>
    <span class="comment"># All methods provided by default, define only those needing overrides</span>
    <span class="comment"># Accessors access the storage in %{$_[0]};</span>
    <span class="comment"># TIEHASH should return a reference to the actual storage</span>
    <span class="keyword">sub</span><span class="variable"> DELETE </span><span class="operator">{</span> <span class="operator">...</span> <span class="operator">}</span>
</pre>
<pre>
    <span class="keyword">package</span> <span class="variable">NewExtraHash</span><span class="operator">;</span>
    <span class="keyword">require</span> <span class="variable">Tie::Hash</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">@ISA</span> <span class="operator">=</span> <span class="operator">(</span><span class="variable">Tie::ExtraHash</span><span class="operator">);</span>
</pre>
<pre>
    <span class="comment"># All methods provided by default, define only those needing overrides</span>
    <span class="comment"># Accessors access the storage in %{$_[0][0]};</span>
    <span class="comment"># TIEHASH should return an array reference with the first element being</span>
    <span class="comment"># the reference to the actual storage </span>
    <span class="keyword">sub</span><span class="variable"> DELETE </span><span class="operator">{</span> 
      <span class="variable">$_</span><span class="operator">[</span><span class="number">0</span><span class="operator">][</span><span class="number">1</span><span class="operator">]</span><span class="operator">-&gt;(</span><span class="string">'del'</span><span class="operator">,</span> <span class="variable">$_</span><span class="operator">[</span><span class="number">0</span><span class="operator">][</span><span class="number">0</span><span class="operator">]</span><span class="operator">,</span> <span class="variable">$_</span><span class="operator">[</span><span class="number">1</span><span class="operator">]</span><span class="operator">);</span> <span class="comment"># Call the report writer</span>
      <span class="keyword">delete</span> <span class="variable">$_</span><span class="operator">[</span><span class="number">0</span><span class="operator">][</span><span class="number">0</span><span class="operator">]</span><span class="operator">-&gt;</span><span class="operator">{</span><span class="variable">$_</span><span class="operator">[</span><span class="number">1</span><span class="operator">]}</span><span class="operator">;</span>           <span class="comment">#  $_[0]-&gt;SUPER::DELETE($_[1])</span>
    <span class="operator">}</span>
</pre>
<pre>
    <span class="keyword">package</span> <span class="variable">main</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">tie</span> <span class="variable">%new_hash</span><span class="operator">,</span> <span class="string">'NewHash'</span><span class="operator">;</span>
    <span class="keyword">tie</span> <span class="variable">%new_std_hash</span><span class="operator">,</span> <span class="string">'NewStdHash'</span><span class="operator">;</span>
    <span class="keyword">tie</span> <span class="variable">%new_extra_hash</span><span class="operator">,</span> <span class="string">'NewExtraHash'</span><span class="operator">,</span>
        <span class="keyword">sub</span><span class="variable"> </span><span class="operator">{</span><span class="keyword">warn</span> <span class="string">"Doing \U$_[1]\E of $_[2].\n"</span><span class="operator">};</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module provides some skeletal methods for hash-tying classes. See
<a href="../../lib/Pod/perltie.html">the perltie manpage</a> for a list of the functions required in order to tie a hash
to a package. The basic <strong>Tie::Hash</strong> package provides a <code>new</code> method, as well
as methods <code>TIEHASH</code>, <code>EXISTS</code> and <code>CLEAR</code>. The <strong>Tie::StdHash</strong> and
<strong>Tie::ExtraHash</strong> packages
provide most methods for hashes described in <a href="../../lib/Pod/perltie.html">the perltie manpage</a> (the exceptions
are <code>UNTIE</code> and <code>DESTROY</code>).  They cause tied hashes to behave exactly like standard hashes,
and allow for selective overwriting of methods.  <strong>Tie::Hash</strong> grandfathers the
<code>new</code> method: it is used if <code>TIEHASH</code> is not defined
in the case a class forgets to include a <code>TIEHASH</code> method.</p>
<p>For developers wishing to write their own tied hashes, the required methods
are briefly defined below. See the <a href="../../lib/Pod/perltie.html">the perltie manpage</a> section for more detailed
descriptive, as well as example code:</p>
<dl>
<dt><strong><a name="item_tiehash_classname_2c_list">TIEHASH classname, LIST</a></strong>

<dd>
<p>The method invoked by the command <code>tie %hash, classname</code>. Associates a new
hash instance with the specified class. <code>LIST</code> would represent additional
arguments (along the lines of <a href="../../lib/AnyDBM_File.html">the AnyDBM_File manpage</a> and compatriots) needed to
complete the association.</p>
</dd>
</li>
<dt><strong><a name="item_store_this_2c_key_2c_value">STORE this, key, value</a></strong>

<dd>
<p>Store datum <em>value</em> into <em>key</em> for the tied hash <em>this</em>.</p>
</dd>
</li>
<dt><strong><a name="item_fetch_this_2c_key">FETCH this, key</a></strong>

⌨️ 快捷键说明

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