stat.html

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

HTML
123
字号
<?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::stat - by-name interface to Perl's built-in stat functions</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::stat - by-name interface to Perl's built-in stat functions</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="#bugs">BUGS</a></li>
	<li><a href="#note">NOTE</a></li>
	<li><a href="#author">AUTHOR</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>File::stat - by-name interface to Perl's built-in <a href="../../lib/Pod/perlfunc.html#item_stat"><code>stat()</code></a> functions</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
 <span class="keyword">use</span> <span class="variable">File::stat</span><span class="operator">;</span>
 <span class="variable">$st</span> <span class="operator">=</span> <span class="keyword">stat</span><span class="operator">(</span><span class="variable">$file</span><span class="operator">)</span> <span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"No $file: $!"</span><span class="operator">;</span>
 <span class="keyword">if</span> <span class="operator">(</span> <span class="operator">(</span><span class="variable">$st</span><span class="operator">-&gt;</span><span class="variable">mode</span> <span class="operator">&amp;</span> <span class="number">0111</span><span class="operator">)</span> <span class="operator">&amp;&amp;</span> <span class="variable">$st</span><span class="operator">-&gt;</span><span class="variable">nlink</span> <span class="operator">&gt;</span> <span class="number">1</span><span class="operator">)</span> <span class="operator">)</span> <span class="operator">{</span>
     <span class="keyword">print</span> <span class="string">"$file is executable with lotsa links\n"</span><span class="operator">;</span>
 <span class="operator">}</span>
</pre>
<pre>
 <span class="keyword">use</span> <span class="variable">File::stat</span> <span class="string">qw(:FIELDS)</span><span class="operator">;</span>
 <span class="keyword">stat</span><span class="operator">(</span><span class="variable">$file</span><span class="operator">)</span> <span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"No $file: $!"</span><span class="operator">;</span>
 <span class="keyword">if</span> <span class="operator">(</span> <span class="operator">(</span><span class="variable">$st_mode</span> <span class="operator">&amp;</span> <span class="number">0111</span><span class="operator">)</span> <span class="operator">&amp;&amp;</span> <span class="variable">$st_nlink</span> <span class="operator">&gt;</span> <span class="number">1</span><span class="operator">)</span> <span class="operator">)</span> <span class="operator">{</span>
     <span class="keyword">print</span> <span class="string">"$file is executable with lotsa links\n"</span><span class="operator">;</span>
 <span class="operator">}</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module's default exports override the core <a href="../../lib/Pod/perlfunc.html#item_stat"><code>stat()</code></a> 
and <a href="../../lib/Pod/perlfunc.html#item_lstat"><code>lstat()</code></a> functions, replacing them with versions that return 
&quot;File::stat&quot; objects.  This object has methods that
return the similarly named structure field name from the
<a href="../../lib/Pod/perlfunc.html#item_stat"><code>stat(2)</code></a> function; namely,
dev,
ino,
mode,
nlink,
uid,
gid,
rdev,
size,
atime,
mtime,
ctime,
blksize,
and
blocks.</p>
<p>You may also import all the structure fields directly into your namespace
as regular variables using the :FIELDS import tag.  (Note that this still
overrides your <a href="../../lib/Pod/perlfunc.html#item_stat"><code>stat()</code></a> and <a href="../../lib/Pod/perlfunc.html#item_lstat"><code>lstat()</code></a> functions.)  Access these fields as
variables named with a preceding <code>st_</code> in front their method names.
Thus, <code>$stat_obj-&gt;dev()</code> corresponds to $st_dev if you import
the fields.</p>
<p>To access this functionality without the core overrides,
pass the <a href="../../lib/Pod/perlfunc.html#item_use"><code>use</code></a> an empty import list, and then access
function functions with their full qualified names.
On the other hand, the built-ins are still available
via the <code>CORE::</code> pseudo-package.</p>
<p>
</p>
<hr />
<h1><a name="bugs">BUGS</a></h1>
<p>As of Perl 5.8.0 after using this module you cannot use the implicit
<a href="../../lib/Pod/perlvar.html#item___"><code>$_</code></a> or the special filehandle <code>_</code> with <a href="../../lib/Pod/perlfunc.html#item_stat"><code>stat()</code></a> or lstat(), trying
to do so leads into strange errors.  The workaround is for <a href="../../lib/Pod/perlvar.html#item___"><code>$_</code></a> to
be explicit</p>
<pre>
    <span class="keyword">my</span> <span class="variable">$stat_obj</span> <span class="operator">=</span> <span class="keyword">stat</span> <span class="variable">$_</span><span class="operator">;</span>
</pre>
<p>and for <code>_</code> to explicitly populate the object using the unexported
and undocumented <code>populate()</code> function with CORE::stat():</p>
<pre>
    <span class="keyword">my</span> <span class="variable">$stat_obj</span> <span class="operator">=</span> <span class="variable">File::stat::populate</span><span class="operator">(</span><span class="variable">CORE::stat</span><span class="operator">(</span><span class="variable">_</span><span class="operator">));</span>
</pre>
<p>
</p>
<hr />
<h1><a name="note">NOTE</a></h1>
<p>While this class is currently implemented using the Class::Struct
module to build a struct-like class, you shouldn't rely upon this.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Tom Christiansen</p>

</body>

</html>

⌨️ 快捷键说明

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