counterfile.html

来自「perl教程」· HTML 代码 · 共 101 行

HTML
101
字号
<?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>File::CounterFile - Persistent counter class</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>File::CounterFile - Persistent counter class</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="#copyright">COPYRIGHT</a></li>
	<li><a href="#author">AUTHOR</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>File::CounterFile - Persistent counter class</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
 <span class="keyword">use</span> <span class="variable">File::CounterFile</span><span class="operator">;</span>
 <span class="variable">$c</span> <span class="operator">=</span> <span class="variable">File::CounterFile</span><span class="operator">-&gt;</span><span class="variable">new</span><span class="operator">(</span><span class="string">"COUNTER"</span><span class="operator">,</span> <span class="string">"aa00"</span><span class="operator">);</span>
</pre>
<pre>
 <span class="variable">$id</span> <span class="operator">=</span> <span class="variable">$c</span><span class="operator">-&gt;</span><span class="variable">inc</span><span class="operator">;</span>
 <span class="keyword">open</span><span class="operator">(</span><span class="variable">F</span><span class="operator">,</span> <span class="string">"&gt;F$id"</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module implements a persistent counter class.  Each counter is
represented by a separate file in the file system.  File locking is
applied, so multiple processes can attempt to access a counter
simultaneously without risk of counter destruction.</p>
<p>You give the file name as the first parameter to the object
constructor (<code>new</code>).  The file is created if it does not exist.</p>
<p>If the file name does not start with &quot;/&quot; or &quot;.&quot;, then it is
interpreted as a file relative to <code>$File::CounterFile::DEFAULT_DIR</code>.
The default value for this variable is initialized from the
environment variable <code>TMPDIR</code>, or <em>/usr/tmp</em> if no environment
variable is defined.  You may want to assign a different value to this
variable before creating counters.</p>
<p>If you pass a second parameter to the constructor, it sets the
initial value for a new counter.  This parameter only takes effect
when the file is created (i.e. it does not exist before the call).</p>
<p>When you call the <code>inc()</code> method, you increment the counter value by
one. When you call <code>dec()</code>, the counter value is decremented.  In both
cases the new value is returned.  The <code>dec()</code> method only works for
numerical counters (digits only).</p>
<p>You can peek at the value of the counter (without incrementing it) by
using the <code>value()</code> method.</p>
<p>The counter can be locked and unlocked with the <a href="../../lib/Pod/perlfunc.html#item_lock"><code>lock()</code></a> and
<code>unlock()</code> methods.  Incrementing and value retrieval are faster when
the counter is locked, because we do not have to update the counter
file all the time.  You can query whether the counter is locked with
the <code>locked()</code> method.</p>
<p>There is also an operator overloading interface to the
File::CounterFile object.  This means that you can use the <code>++</code>
operator for incrementing and the <code>--</code> operator for decrementing the counter,
and you can interpolate counters directly into strings.</p>
<p>
</p>
<hr />
<h1><a name="copyright">COPYRIGHT</a></h1>
<p>Copyright (c) 1995-1998,2002,2003 Gisle Aas. All rights reserved.</p>
<p>This library is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Gisle Aas &lt;<a href="mailto:gisle@aas.no">gisle@aas.no</a>&gt;</p>

</body>

</html>

⌨️ 快捷键说明

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