glob.html
来自「perl教程」· HTML 代码 · 共 373 行 · 第 1/2 页
HTML
373 行
provided to simplify implementing the historic <code>csh(1)</code> globbing
behaviour and should probably not be used anywhere else.</p>
</dd>
</li>
<dt><strong><a name="item_glob_quote"><code>GLOB_QUOTE</code></a></strong>
<dd>
<p>Use the backslash ('\') character for quoting: every occurrence of a
backslash followed by a character in the pattern is replaced by that
character, avoiding any special interpretation of the character.
(But see below for exceptions on DOSISH systems).</p>
</dd>
</li>
<dt><strong><a name="item_glob_tilde"><code>GLOB_TILDE</code></a></strong>
<dd>
<p>Expand patterns that start with '~' to user name home directories.</p>
</dd>
</li>
<dt><strong><a name="item_glob_csh"><code>GLOB_CSH</code></a></strong>
<dd>
<p>For convenience, <a href="#item_glob_csh"><code>GLOB_CSH</code></a> is a synonym for
<code>GLOB_BRACE | GLOB_NOMAGIC | GLOB_QUOTE | GLOB_TILDE | GLOB_ALPHASORT</code>.</p>
</dd>
</li>
</dl>
<p>The POSIX provided <code>GLOB_APPEND</code>, <code>GLOB_DOOFFS</code>, and the FreeBSD
extensions <code>GLOB_ALTDIRFUNC</code>, and <code>GLOB_MAGCHAR</code> flags have not been
implemented in the Perl version because they involve more complex
interaction with the underlying C structures.</p>
<p>The following flag has been added in the Perl implementation for
csh compatibility:</p>
<dl>
<dt><strong><a name="item_glob_alphasort"><code>GLOB_ALPHASORT</code></a></strong>
<dd>
<p>If <a href="#item_glob_nosort"><code>GLOB_NOSORT</code></a> is not in effect, sort filenames is alphabetical
order (case does not matter) rather than in ASCII order.</p>
</dd>
</li>
</dl>
<p>
</p>
<hr />
<h1><a name="diagnostics">DIAGNOSTICS</a></h1>
<p><code>bsd_glob()</code> returns a list of matching paths, possibly zero length. If an
error occurred, &File::Glob::GLOB_ERROR will be non-zero and <a href="../../lib/Pod/perlvar.html#item___"><code>$!</code></a> will be
set. &File::Glob::GLOB_ERROR is guaranteed to be zero if no error occurred,
or one of the following values otherwise:</p>
<dl>
<dt><strong><a name="item_glob_nospace"><code>GLOB_NOSPACE</code></a></strong>
<dd>
<p>An attempt to allocate memory failed.</p>
</dd>
</li>
<dt><strong><a name="item_glob_abend"><code>GLOB_ABEND</code></a></strong>
<dd>
<p>The glob was stopped because an error was encountered.</p>
</dd>
</li>
</dl>
<p>In the case where <code>bsd_glob()</code> has found some matching paths, but is
interrupted by an error, it will return a list of filenames <strong>and</strong>
set &File::Glob::ERROR.</p>
<p>Note that <code>bsd_glob()</code> deviates from POSIX and FreeBSD <a href="../../lib/Pod/perlfunc.html#item_glob"><code>glob(3)</code></a> behaviour
by not considering <code>ENOENT</code> and <code>ENOTDIR</code> as errors - <code>bsd_glob()</code> will
continue processing despite those errors, unless the <a href="#item_glob_err"><code>GLOB_ERR</code></a> flag is
set.</p>
<p>Be aware that all filenames returned from File::Glob are tainted.</p>
<p>
</p>
<hr />
<h1><a name="notes">NOTES</a></h1>
<ul>
<li>
<p>If you want to use multiple patterns, e.g. <code>bsd_glob("a* b*")</code>, you should
probably throw them in a set as in <code>bsd_glob("{a*,b*}")</code>. This is because
the argument to <code>bsd_glob()</code> isn't subjected to parsing by the C shell.
Remember that you can use a backslash to escape things.</p>
</li>
<li>
<p>On DOSISH systems, backslash is a valid directory separator character.
In this case, use of backslash as a quoting character (via GLOB_QUOTE)
interferes with the use of backslash as a directory separator. The
best (simplest, most portable) solution is to use forward slashes for
directory separators, and backslashes for quoting. However, this does
not match "normal practice" on these systems. As a concession to user
expectation, therefore, backslashes (under GLOB_QUOTE) only quote the
glob metacharacters '[', ']', '{', '}', '-', '~', and backslash itself.
All other backslashes are passed through unchanged.</p>
</li>
<li>
<p>Win32 users should use the real slash. If you really want to use
backslashes, consider using Sarathy's File::DosGlob, which comes with
the standard Perl distribution.</p>
</li>
<li>
<p>Mac OS (Classic) users should note a few differences. Since
Mac OS is not Unix, when the glob code encounters a tilde glob (e.g.
~user) and the <a href="#item_glob_tilde"><code>GLOB_TILDE</code></a> flag is used, it simply returns that
pattern without doing any expansion.</p>
<p>Glob on Mac OS is case-insensitive by default (if you don't use any
flags). If you specify any flags at all and still want glob
to be case-insensitive, you must include <a href="#item_glob_nocase"><code>GLOB_NOCASE</code></a> in the flags.</p>
<p>The path separator is ':' (aka colon), not '/' (aka slash). Mac OS users
should be careful about specifying relative pathnames. While a full path
always begins with a volume name, a relative pathname should always
begin with a ':'. If specifying a volume name only, a trailing ':' is
required.</p>
<p>The specification of pathnames in glob patterns adheres to the usual Mac
OS conventions: The path separator is a colon ':', not a slash '/'. A
full path always begins with a volume name. A relative pathname on Mac
OS must always begin with a ':', except when specifying a file or
directory name in the current working directory, where the leading colon
is optional. If specifying a volume name only, a trailing ':' is
required. Due to these rules, a glob like <*:> will find all
mounted volumes, while a glob like <*> or <:*> will find
all files and directories in the current directory.</p>
<p>Note that updirs in the glob pattern are resolved before the matching begins,
i.e. a pattern like "*HD:t?p::a*" will be matched as "*HD:a*". Note also,
that a single trailing ':' in the pattern is ignored (unless it's a volume
name pattern like "*HD:"), i.e. a glob like <:*:> will find both
directories <em>and</em> files (and not, as one might expect, only directories).
You can, however, use the <a href="#item_glob_mark"><code>GLOB_MARK</code></a> flag to distinguish (without a file
test) directory names from file names.</p>
<p>If the <a href="#item_glob_mark"><code>GLOB_MARK</code></a> flag is set, all directory paths will have a ':' appended.
Since a directory like 'lib:' is <em>not</em> a valid <em>relative</em> path on Mac OS,
both a leading and a trailing colon will be added, when the directory name in
question doesn't contain any colons (e.g. 'lib' becomes ':lib:').</p>
</li>
</ul>
<p>
</p>
<hr />
<h1><a name="see_also">SEE ALSO</a></h1>
<p><a href="../../lib/Pod/perlfunc.html#glob">glob in the perlfunc manpage</a>, <a href="../../lib/Pod/perlfunc.html#item_glob"><code>glob(3)</code></a></p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>The Perl interface was written by Nathan Torkington <<a href="mailto:gnat@frii.com">gnat@frii.com</a>>,
and is released under the artistic license. Further modifications were
made by Greg Bacon <<a href="mailto:gbacon@cs.uah.edu">gbacon@cs.uah.edu</a>>, Gurusamy Sarathy
<<a href="mailto:gsar@activestate.com">gsar@activestate.com</a>>, and Thomas Wegner
<<a href="mailto:wegner_thomas@yahoo.com">wegner_thomas@yahoo.com</a>>. The C glob code has the
following copyright:</p>
<pre>
Copyright (c) 1989, 1993 The Regents of the University of California.
All rights reserved.</pre>
<pre>
This code is derived from software contributed to Berkeley by
Guido van Rossum.</pre>
<pre>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:</pre>
<pre>
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.</pre>
<pre>
<span class="variable">THIS</span> <span class="variable">SOFTWARE</span> <span class="variable">IS</span> <span class="variable">PROVIDED</span> <span class="variable">BY</span> <span class="variable">THE</span> <span class="variable">REGENTS</span> <span class="variable">AND</span> <span class="variable">CONTRIBUTORS</span> <span class="string">``</span><span class="variable">AS</span> <span class="variable">IS</span><span class="string">''</span> <span class="variable">AND</span>
<span class="variable">ANY</span> <span class="variable">EXPRESS</span> <span class="variable">OR</span> <span class="variable">IMPLIED</span> <span class="variable">WARRANTIES</span><span class="operator">,</span> <span class="variable">INCLUDING</span><span class="operator">,</span> <span class="variable">BUT</span> <span class="variable">NOT</span> <span class="variable">LIMITED</span> <span class="variable">TO</span><span class="operator">,</span> <span class="variable">THE</span>
<span class="variable">IMPLIED</span> <span class="variable">WARRANTIES</span> <span class="variable">OF</span> <span class="variable">MERCHANTABILITY</span> <span class="variable">AND</span> <span class="variable">FITNESS</span> <span class="variable">FOR</span> <span class="variable">A</span> <span class="variable">PARTICULAR</span> <span class="variable">PURPOSE</span>
<span class="variable">ARE</span> <span class="variable">DISCLAIMED</span><span class="operator">.</span> <span class="variable">IN</span> <span class="variable">NO</span> <span class="variable">EVENT</span> <span class="variable">SHALL</span> <span class="variable">THE</span> <span class="variable">REGENTS</span> <span class="variable">OR</span> <span class="variable">CONTRIBUTORS</span> <span class="variable">BE</span> <span class="variable">LIABLE</span>
<span class="variable">FOR</span> <span class="variable">ANY</span> <span class="variable">DIRECT</span><span class="operator">,</span> <span class="variable">INDIRECT</span><span class="operator">,</span> <span class="variable">INCIDENTAL</span><span class="operator">,</span> <span class="variable">SPECIAL</span><span class="operator">,</span> <span class="variable">EXEMPLARY</span><span class="operator">,</span> <span class="variable">OR</span> <span class="variable">CONSEQUENTIAL</span>
<span class="variable">DAMAGES</span> <span class="operator">(</span><span class="variable">INCLUDING</span><span class="operator">,</span> <span class="variable">BUT</span> <span class="variable">NOT</span> <span class="variable">LIMITED</span> <span class="variable">TO</span><span class="operator">,</span> <span class="variable">PROCUREMENT</span> <span class="variable">OF</span> <span class="variable">SUBSTITUTE</span> <span class="variable">GOODS</span>
<span class="variable">OR</span> <span class="variable">SERVICES</span><span class="operator">;</span> <span class="variable">LOSS</span> <span class="variable">OF</span> <span class="variable">USE</span><span class="operator">,</span> <span class="variable">DATA</span><span class="operator">,</span> <span class="variable">OR</span> <span class="variable">PROFITS</span><span class="operator">;</span> <span class="variable">OR</span> <span class="variable">BUSINESS</span> <span class="variable">INTERRUPTION</span><span class="operator">)</span>
<span class="variable">HOWEVER</span> <span class="variable">CAUSED</span> <span class="variable">AND</span> <span class="variable">ON</span> <span class="variable">ANY</span> <span class="variable">THEORY</span> <span class="variable">OF</span> <span class="variable">LIABILITY</span><span class="operator">,</span> <span class="variable">WHETHER</span> <span class="variable">IN</span> <span class="variable">CONTRACT</span><span class="operator">,</span> <span class="variable">STRICT</span>
<span class="variable">LIABILITY</span><span class="operator">,</span> <span class="variable">OR</span> <span class="variable">TORT</span> <span class="operator">(</span><span class="variable">INCLUDING</span> <span class="variable">NEGLIGENCE</span> <span class="variable">OR</span> <span class="variable">OTHERWISE</span><span class="operator">)</span> <span class="variable">ARISING</span> <span class="variable">IN</span> <span class="variable">ANY</span> <span class="variable">WAY</span>
<span class="variable">OUT</span> <span class="variable">OF</span> <span class="variable">THE</span> <span class="variable">USE</span> <span class="variable">OF</span> <span class="variable">THIS</span> <span class="variable">SOFTWARE</span><span class="operator">,</span> <span class="variable">EVEN</span> <span class="variable">IF</span> <span class="variable">ADVISED</span> <span class="variable">OF</span> <span class="variable">THE</span> <span class="variable">POSSIBILITY</span> <span class="variable">OF</span>
<span class="variable">SUCH</span> <span class="variable">DAMAGE</span><span class="operator">.</span>
</pre>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?