listing.html

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

HTML
97
字号
<?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::Listing - parse directory listing</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::Listing - parse directory listing</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="#credits">CREDITS</a></li>
</ul>
<!-- INDEX END -->

<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>File::Listing - parse directory listing</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
 <span class="keyword">use</span> <span class="variable">File::Listing</span> <span class="string">qw(parse_dir)</span><span class="operator">;</span>
 <span class="keyword">for</span> <span class="operator">(</span><span class="variable">parse_dir</span><span class="operator">(</span><span class="string">`ls -l`</span><span class="operator">))</span> <span class="operator">{</span>
     <span class="operator">(</span><span class="variable">$name</span><span class="operator">,</span> <span class="variable">$type</span><span class="operator">,</span> <span class="variable">$size</span><span class="operator">,</span> <span class="variable">$mtime</span><span class="operator">,</span> <span class="variable">$mode</span><span class="operator">)</span> <span class="operator">=</span> <span class="variable">@$_</span><span class="operator">;</span>
     <span class="keyword">next</span> <span class="keyword">if</span> <span class="variable">$type</span> <span class="keyword">ne</span> <span class="string">'f'</span><span class="operator">;</span> <span class="comment"># plain file</span>
     <span class="comment">#...</span>
 <span class="operator">}</span>
</pre>
<pre>
 <span class="comment"># directory listing can also be read from a file</span>
 <span class="keyword">open</span><span class="operator">(</span><span class="variable">LISTING</span><span class="operator">,</span> <span class="string">"zcat ls-lR.gz|"</span><span class="operator">);</span>
 <span class="variable">$dir</span> <span class="operator">=</span> <span class="variable">parse_dir</span><span class="operator">(\</span><span class="variable">*LISTING</span><span class="operator">,</span> <span class="string">'+0000'</span><span class="operator">);</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>This module exports a single function called parse_dir(), which can be
used to parse directory listings. Currently it only understand Unix
<code>'ls -l'</code> and <code>'ls -lR'</code> format.  It should eventually be able to
most things you might get back from a ftp server file listing (LIST
command), i.e. VMS listings, NT listings, DOS listings,...</p>
<p>The first parameter to <code>parse_dir()</code> is the directory listing to parse.
It can be a scalar, a reference to an array of directory lines or a
glob representing a filehandle to read the directory listing from.</p>
<p>The second parameter is the time zone to use when parsing time stamps
in the listing. If this value is undefined, then the local time zone is
assumed.</p>
<p>The third parameter is the type of listing to assume.  The values will
be strings like 'unix', 'vms', 'dos'.  Currently only 'unix' is
implemented and this is also the default value.  Ideally, the listing
type should be determined automatically.</p>
<p>The fourth parameter specifies how unparseable lines should be treated.
Values can be 'ignore', 'warn' or a code reference.  Warn means that
the perl <a href="../../lib/Pod/perlfunc.html#item_warn"><code>warn()</code></a> function will be called.  If a code reference is
passed, then this routine will be called and the return value from it
will be incorporated in the listing.  The default is 'ignore'.</p>
<p>Only the first parameter is mandatory.</p>
<p>The return value from <code>parse_dir()</code> is a list of directory entries.  In
a scalar context the return value is a reference to the list.  The
directory entries are represented by an array consisting of [
$filename, $filetype, $filesize, $filetime, $filemode ].  The
$filetype value is one of the letters 'f', 'd', 'l' or '?'.  The
$filetime value is the seconds since Jan 1, 1970.  The
$filemode is a bitmask like the mode returned by stat().</p>
<p>
</p>
<hr />
<h1><a name="credits">CREDITS</a></h1>
<p>Based on lsparse.pl (from Lee McLoughlin's ftp mirror package) and
Net::FTP's parse_dir (Graham Barr).</p>

</body>

</html>

⌨️ 快捷键说明

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