⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch05_02.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
📖 第 1 页 / 共 5 页
字号:
Removes a lock from the file.</p></dd><dt><a name="<tt class="literal">LOCK_NB</tt> (4)"><b><tt class="literal">LOCK_NB</tt> (4)</b></dt><dd>Prevents <tt class="literal">flock</tt> from blocking while trying toestablish a lock with <tt class="literal">LOCK_SH</tt> or<tt class="literal">LOCK_EX</tt> and instructs it to return immediately.<tt class="literal">LOCK_NB</tt> must be <em class="emphasis">or</em>ed with theother operation as an expression for the operation argument, i.e.,<tt class="literal">(LOCK_EX |</tt> <tt class="literal">LOCK_NB)</tt>.</p></dd></dl></div><a name="INDEX-946" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="fork"><b>fork</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>fork</pre></td><td align="right" /></tr></table><a name="INDEX-946" />Spawns a childprocess that executes the code immediately following the<tt class="literal">fork</tt> call until the process is terminated (usuallywith an <tt class="literal">exit</tt>). The child process runs parallel tothe parent process and shares all the parent'svariables and open filehandles. The function returns the child pid tothe parent process and <tt class="literal">0</tt> to the child process onsuccess. If it fails, it returns the undefined value to the parentprocess, and no child process is created. If you<tt class="literal">fork</tt> your child processes, you'llhave to <tt class="literal">wait</tt> on their zombies when they die. The<tt class="literal">fork</tt> function is unlikely to be implemented on anyoperating system not resembling Unix, unless it purports POSIXcompliance.</p></div><a name="INDEX-947" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="formline"><b>formline</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>formline <em class="emphasis">picture</em>, <em class="emphasis">variables</em></pre></td><td align="right" /></tr></table><a name="INDEX-947" />Internal functionused by formats, although you may also call it. It formats a list ofvalues (<em class="replaceable"><tt>variables</tt></em>) according to thecontents of <em class="replaceable"><tt>picture</tt></em>, placing the outputinto the format output accumulator, <tt class="literal">$^A</tt>. When a<tt class="literal">write</tt> is done, the contents of<tt class="literal">$^A</tt> are written to a filehandle, but you can alsoread <tt class="literal">$^A</tt> yourself and set <tt class="literal">$^A</tt>back to "". Note that a formattypically does one <tt class="literal">formline</tt> per line of form, butthe <tt class="literal">formline</tt> function itselfdoesn't care how many newlines are embedded in the<em class="replaceable"><tt>picture</tt></em>. This means that the<tt class="literal">~</tt> and <tt class="literal">~~</tt> tokens will treat theentire <em class="replaceable"><tt>picture</tt></em> as a single line. Thus, youmay need to use multiple formlines to implement a single-recordformat, such as the format compiler.</p><p>Be careful if you put double quotes around the picture, since an<tt class="literal">@</tt> character may be taken to mean the beginning ofan array name. <tt class="literal">formline</tt> always returns true. See<a href="ch04_01.htm">Chapter 4, "The Perl Language"</a> for more information.</p></div><a name="INDEX-948" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getc"><b>getc</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>getc <em class="emphasis">filehandle</em></pre></td><td align="right" /></tr></table><a name="INDEX-948" />Returns the next bytefrom the input file attached to<em class="replaceable"><tt>filehandle</tt></em>. At end-of-file, it returns anull string. If <em class="replaceable"><tt>filehandle</tt></em> is omitted, thefunction reads from STDIN. This operator is very slow, but isoccasionally useful for single-character input from the keyboard.</p></div><a name="INDEX-949" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getgrent"><b>getgrent</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>getgrent</pre></td><td align="right" /></tr></table><a name="INDEX-949" />Returns the nextentry from the systems group file (usually<em class="emphasis">/etc/group</em> on Unix systems) starting from thetop. Returns null when end-of-file is reached. The return value from<tt class="literal">getgrent</tt> in list context is:</p><blockquote><pre class="code">($name, $passwd, $gid, $members)</pre></blockquote><p>in which <tt class="literal">$members</tt> contains a space-separated listof the login names of the members of the group. In scalar context,<tt class="literal">getgrent</tt> returns only the group name.</p></div><a name="INDEX-950" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getgrgid"><b>getgrgid</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>getgrgid <em class="emphasis">gid</em></pre></td><td align="right" /></tr></table><a name="INDEX-950" />Retrieves a groupfile (<em class="emphasis">/etc/group</em>) entry by group number<em class="replaceable"><tt>gid</tt></em>. The return value in list context is:</p><blockquote><pre class="code">($name, $passwd, $gid, $members)</pre></blockquote><p>in which <tt class="literal">$members</tt> contains a space-separated listof the login names of the members of the group. If you want to dothis repeatedly, consider caching the data in a hash using<tt class="literal">getgrent</tt>. In scalar context,<tt class="literal">getgrgid</tt> returns only the group name.</p></div><a name="INDEX-951" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getgrnam"><b>getgrnam</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>getgrnam <em class="emphasis">name</em></pre></td><td align="right" /></tr></table><a name="INDEX-951" />Retrieves a groupfile entry by the group name <em class="replaceable"><tt>name</tt></em>. Thereturn value in list context is:</p><blockquote><pre class="code">($name, $passwd, $gid, $members)</pre></blockquote><p>in which <tt class="literal">$members</tt> contains a space-separated listof the login names of the members of the group. In scalar context,<tt class="literal">getgrnam</tt> returns only the numeric group ID.</p></div><a name="INDEX-952" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="gethostbyaddr"><b>gethostbyaddr</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>gethostbyaddr <em class="emphasis">address</em>, [<em class="emphasis">addrtype</em>]</pre></td><td align="right" /></tr></table><a name="INDEX-952" />Retrievesthe hostname (and alternate addresses) of a packed binary network<em class="replaceable"><tt>address</tt></em>.(<em class="replaceable"><tt>addrtype</tt></em> indicates the type of addressgiven. Since <tt class="literal">gethostbyaddr</tt> is used almost solelyfor Internet IP addresses, <em class="replaceable"><tt>addrtype</tt></em> is notneeded.) The return value in list context is:</p><blockquote><pre class="code">($name, $aliases, $addrtype, $length, @addrs)</pre></blockquote><p>in which <tt class="literal">@addrs</tt> is a list of packed binaryaddresses. In the Internet domain, each address is four bytes longand can be unpacked by something like:</p><blockquote><pre class="code">($a, $b, $c, $d) = unpack('C4', $addrs[0]);</pre></blockquote><p>In scalar context, <tt class="literal">gethostbyaddr</tt> returns only thehostname.</p></div><a name="INDEX-953" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="gethostbyname"><b>gethostbyname</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>gethostbyname <em class="emphasis">name</em></pre></td><td align="right" /></tr></table><a name="INDEX-953" />Retrievesthe address (and other names) of a network hostname. The return valuein list context is:</p><blockquote><pre class="code">($name, $aliases, $addrtype, $length, @addrs)</pre></blockquote><p>in which <tt class="literal">@addrs</tt> is a list of raw addresses. Inscalar context, <tt class="literal">gethostbyname</tt> returns only thehost address.</p></div><a name="INDEX-954" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="gethostent"><b>gethostent</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>gethostent</pre></td><td align="right" /></tr></table><a name="INDEX-954" />Retrieves thenext entry from your system's network hosts file(usually <em class="emphasis">/etc/hosts</em> on Unix). The return valuefrom <tt class="literal">gethostent</tt> is:</p><blockquote><pre class="code">($name, $aliases, $addrtype, $length, @addrs)</pre></blockquote><p>in which <tt class="literal">@addrs</tt> is a list of raw addresses.Scripts that use this function should not be considered portable.</p></div><a name="INDEX-955" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getlogin"><b>getlogin</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>getlogin</pre></td><td align="right" /></tr></table><a name="INDEX-955" />Returns thecurrent login from <em class="emphasis">/etc/utmp</em> (Unix systemsonly), if any. If null, use <tt class="literal">getpwuid</tt>. For example:</p><blockquote><pre class="code">$login = getlogin || getpwuid($&lt;) || "Intruder!!";</pre></blockquote></div><a name="INDEX-956" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getnetbyaddr"><b>getnetbyaddr</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>getnetbyaddr <em class="emphasis">address</em>, [<em class="emphasis">addrtype</em>]</pre></td><td align="right" /></tr></table><a name="INDEX-956" />Retrieves thenetwork name or names of the given network<em class="replaceable"><tt>address</tt></em>.(<em class="replaceable"><tt>addrtype</tt></em> indicates the type of address.Often, this function is used for IP addresses, in which the type isnot needed.) The return value in list context is:</p><blockquote><pre class="code">($name, $aliases, $addrtype, $net)</pre></blockquote><p>In scalar context, <tt class="literal">getnetbyaddr</tt> returns only thenetwork name.</p></div><a name="INDEX-957" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getnetbyname"><b>getnetbyname</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>getnetbyname <em class="emphasis">name</em></pre></td><td align="right" /></tr></table><a name="INDEX-957" />Retrieves thenetwork address of a network <em class="replaceable"><tt>name</tt></em>. Thereturn value in list context is:</p><blockquote><pre class="code">($name, $aliases, $addrtype, $net)</pre></blockquote><p>In scalar context, <tt class="literal">getnetbyname</tt> returns only thenetwork address.</p></div><a name="INDEX-958" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getnetent"><b>getnetent</b></font></td><td align="right"><i></i></td></tr></table><hr width="515" size="3" noshade="true" align="left" color="black" /><table width="515" border="0" cellpadding="5"><tr><td align="left"><pre>getnetent</pre></td><td align="right" /></tr></table><a name="INDEX-958" />Retrieves thenext line from your <em class="emphasis">/etc/networks</em> file, orsystem equivalent. The return value in list context is:</p><blockquote><pre class="code">($name, $aliases, $addrtype, $net)</pre></blockquote><p>In scalar context, <tt class="literal">getnetent</tt> returns only thenetwork name.</p></div><a name="INDEX-959" /><div class="refentry"><table width="515" border="0" cellpadding="5"><tr><td align="left"><font size="+1"><a name="getpeername"><b>getpeername</b></font></td><td align="right"

⌨️ 快捷键说明

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