mac.html
来自「perl教程」· HTML 代码 · 共 530 行 · 第 1/2 页
HTML
530 行
<?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::Spec::Mac - File::Spec for Mac OS</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__',3);</script>
<h1><a>File::Spec::Mac - File::Spec for Mac OS</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="#methods">METHODS</a></li>
<li><a href="#authors">AUTHORS</a></li>
<li><a href="#copyright">COPYRIGHT</a></li>
<li><a href="#see_also">SEE ALSO</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>File::Spec::Mac - File::Spec for Mac OS (Classic)</p>
<p>
</p>
<hr />
<h1><a name="synopsis">SYNOPSIS</a></h1>
<pre>
<span class="keyword">require</span> <span class="variable">File::Spec::Mac</span><span class="operator">;</span> <span class="comment"># Done internally by File::Spec if needed</span>
</pre>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>Methods for manipulating file specifications.</p>
<p>
</p>
<hr />
<h1><a name="methods">METHODS</a></h1>
<dl>
<dt><strong><a name="item_canonpath">canonpath</a></strong>
<dd>
<p>On Mac OS, there's nothing to be done. Returns what it's given.</p>
</dd>
</li>
<dt><strong><a name="item_catdir"><code>catdir()</code></a></strong>
<dd>
<p>Concatenate two or more directory names to form a path separated by colons
(":") ending with a directory. Resulting paths are <strong>relative</strong> by default,
but can be forced to be absolute (but avoid this, see below). Automatically
puts a trailing ":" on the end of the complete path, because that's what's
done in MacPerl's environment and helps to distinguish a file path from a
directory path.</p>
</dd>
<dd>
<p><strong>IMPORTANT NOTE:</strong> Beginning with version 1.3 of this module, the resulting
path is relative by default and <em>not</em> absolute. This decision was made due
to portability reasons. Since <a href="#item_catdir"><code>File::Spec->catdir()</code></a> returns relative paths
on all other operating systems, it will now also follow this convention on Mac
OS. Note that this may break some existing scripts.</p>
</dd>
<dd>
<p>The intended purpose of this routine is to concatenate <em>directory names</em>.
But because of the nature of Macintosh paths, some additional possibilities
are allowed to make using this routine give reasonable results for some
common situations. In other words, you are also allowed to concatenate
<em>paths</em> instead of directory names (strictly speaking, a string like ":a"
is a path, but not a name, since it contains a punctuation character ":").</p>
</dd>
<dd>
<p>So, beside calls like</p>
</dd>
<dd>
<pre>
catdir("a") = ":a:"
catdir("a","b") = ":a:b:"
catdir() = "" (special case)</pre>
</dd>
<dd>
<p>calls like the following</p>
</dd>
<dd>
<pre>
catdir(":a:") = ":a:"
catdir(":a","b") = ":a:b:"
catdir(":a:","b") = ":a:b:"
catdir(":a:",":b:") = ":a:b:"
catdir(":") = ":"</pre>
</dd>
<dd>
<p>are allowed.</p>
</dd>
<dd>
<p>Here are the rules that are used in <a href="#item_catdir"><code>catdir()</code></a>; note that we try to be as
compatible as possible to Unix:</p>
</dd>
<ol>
<li>
<p>The resulting path is relative by default, i.e. the resulting path will have a
leading colon.</p>
</li>
<li>
<p>A trailing colon is added automatically to the resulting path, to denote a
directory.</p>
</li>
<li>
<p>Generally, each argument has one leading ":" and one trailing ":"
removed (if any). They are then joined together by a ":". Special
treatment applies for arguments denoting updir paths like "::lib:",
see (4), or arguments consisting solely of colons ("colon paths"),
see (5).</p>
</li>
<li>
<p>When an updir path like ":::lib::" is passed as argument, the number
of directories to climb up is handled correctly, not removing leading
or trailing colons when necessary. E.g.</p>
<pre>
catdir(":::a","::b","c") = ":::a::b:c:"
catdir(":::a::","::b","c") = ":::a:::b:c:"</pre>
</li>
<li>
<p>Adding a colon ":" or empty string "" to a path at <em>any</em> position
doesn't alter the path, i.e. these arguments are ignored. (When a ""
is passed as the first argument, it has a special meaning, see
(6)). This way, a colon ":" is handled like a "." (curdir) on Unix,
while an empty string "" is generally ignored (see
<a href="#item_canonpath"><code>Unix->canonpath()</code></a> ). Likewise, a "::" is handled like a ".."
(updir), and a ":::" is handled like a "../.." etc. E.g.</p>
<pre>
catdir("a",":",":","b") = ":a:b:"
catdir("a",":","::",":b") = ":a::b:"</pre>
</li>
<li>
<p>If the first argument is an empty string "" or is a volume name, i.e. matches
the pattern /^[^:]+:/, the resulting path is <strong>absolute</strong>.</p>
</li>
<li>
<p>Passing an empty string "" as the first argument to <a href="#item_catdir"><code>catdir()</code></a> is
like passing<a href="#item_rootdir"><code>File::Spec->rootdir()</code></a> as the first argument, i.e.</p>
<pre>
catdir("","a","b") is the same as</pre>
<pre>
catdir(rootdir(),"a","b").</pre>
<p>This is true on Unix, where <a href="#item_catdir"><code>catdir("","a","b")</code></a> yields "/a/b" and
<a href="#item_rootdir"><code>rootdir()</code></a> is "/". Note that <a href="#item_rootdir"><code>rootdir()</code></a> on Mac OS is the startup
volume, which is the closest in concept to Unix' "/". This should help
to run existing scripts originally written for Unix.</p>
</li>
<li>
<p>For absolute paths, some cleanup is done, to ensure that the volume
name isn't immediately followed by updirs. This is invalid, because
this would go beyond "root". Generally, these cases are handled like
their Unix counterparts:</p>
<pre>
Unix:
Unix->catdir("","") = "/"
Unix->catdir("",".") = "/"
Unix->catdir("","..") = "/" # can't go beyond root
Unix->catdir("",".","..","..","a") = "/a"
Mac:
Mac->catdir("","") = rootdir() # (e.g. "HD:")
Mac->catdir("",":") = rootdir()
Mac->catdir("","::") = rootdir() # can't go beyond root
Mac->catdir("",":","::","::","a") = rootdir() . "a:" # (e.g. "HD:a:")</pre>
<p>However, this approach is limited to the first arguments following
"root" (again, see <a href="#item_canonpath"><code>Unix->canonpath()</code></a> ). If there are more
arguments that move up the directory tree, an invalid path going
beyond root can be created.</p>
</li>
</ol>
<p>As you've seen, you can force <a href="#item_catdir"><code>catdir()</code></a> to create an absolute path
by passing either an empty string or a path that begins with a volume
name as the first argument. However, you are strongly encouraged not
to do so, since this is done only for backward compatibility. Newer
versions of File::Spec come with a method called <a href="#item_catpath"><code>catpath()</code></a> (see
below), that is designed to offer a portable solution for the creation
of absolute paths. It takes volume, directory and file portions and
returns an entire path. While <a href="#item_catdir"><code>catdir()</code></a> is still suitable for the
concatenation of <em>directory names</em>, you are encouraged to use
<a href="#item_catpath"><code>catpath()</code></a> to concatenate <em>volume names</em> and <em>directory
paths</em>. E.g.</p>
<pre>
<span class="variable">$dir</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-></span><span class="variable">catdir</span><span class="operator">(</span><span class="string">"tmp"</span><span class="operator">,</span><span class="string">"sources"</span><span class="operator">);</span>
<span class="variable">$abs_path</span> <span class="operator">=</span> <span class="variable">File::Spec</span><span class="operator">-></span><span class="variable">catpath</span><span class="operator">(</span><span class="string">"MacintoshHD:"</span><span class="operator">,</span> <span class="variable">$dir</span><span class="operator">,</span><span class="string">""</span><span class="operator">);</span>
</pre>
<p>yields</p>
<pre>
"MacintoshHD:tmp:sources:" .</pre>
<dt><strong><a name="item_catfile">catfile</a></strong>
<dd>
<p>Concatenate one or more directory names and a filename to form a
complete path ending with a filename. Resulting paths are <strong>relative</strong>
by default, but can be forced to be absolute (but avoid this).</p>
</dd>
<dd>
<p><strong>IMPORTANT NOTE:</strong> Beginning with version 1.3 of this module, the
resulting path is relative by default and <em>not</em> absolute. This
decision was made due to portability reasons. Since
<a href="#item_catfile"><code>File::Spec->catfile()</code></a> returns relative paths on all other
operating systems, it will now also follow this convention on Mac OS.
Note that this may break some existing scripts.</p>
</dd>
<dd>
<p>The last argument is always considered to be the file portion. Since
<a href="#item_catfile"><code>catfile()</code></a> uses <a href="#item_catdir"><code>catdir()</code></a> (see above) for the concatenation of the
directory portions (if any), the following with regard to relative and
absolute paths is true:</p>
</dd>
<dd>
<pre>
catfile("") = ""
catfile("file") = "file"</pre>
</dd>
<dd>
<p>but</p>
</dd>
<dd>
<pre>
catfile("","") = rootdir() # (e.g. "HD:")
catfile("","file") = rootdir() . file # (e.g. "HD:file")
catfile("HD:","file") = "HD:file"</pre>
</dd>
<dd>
<p>This means that <a href="#item_catdir"><code>catdir()</code></a> is called only when there are two or more
arguments, as one might expect.</p>
</dd>
<dd>
<p>Note that the leading ":" is removed from the filename, so that</p>
</dd>
<dd>
<pre>
catfile("a","b","file") = ":a:b:file" and</pre>
</dd>
<dd>
<pre>
catfile("a","b",":file") = ":a:b:file"</pre>
</dd>
<dd>
<p>give the same answer.</p>
</dd>
<dd>
<p>To concatenate <em>volume names</em>, <em>directory paths</em> and <em>filenames</em>,
you are encouraged to use <a href="#item_catpath"><code>catpath()</code></a> (see below).</p>
</dd>
</li>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?