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

📄 ch31_10.htm

📁 编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,
💻 HTM
字号:
<html><head><title>use filetest (Programming Perl)</title><!-- STYLESHEET --><link rel="stylesheet" type="text/css" href="../style/style1.css"><!-- METADATA --><!--Dublin Core Metadata--><meta name="DC.Creator" content=""><meta name="DC.Date" content=""><meta name="DC.Format" content="text/xml" scheme="MIME"><meta name="DC.Generator" content="XSLT stylesheet, xt by James Clark"><meta name="DC.Identifier" content=""><meta name="DC.Language" content="en-US"><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc."><meta name="DC.Source" content="" scheme="ISBN"><meta name="DC.Subject.Keyword" content=""><meta name="DC.Title" content="use filetest"><meta name="DC.Type" content="Text.Monograph"></head><body><!-- START OF BODY --><!-- TOP BANNER --><img src="gifs/smbanner.gif" usemap="#banner-map" border="0" alt="Book Home"><map name="banner-map"><AREA SHAPE="RECT" COORDS="0,0,466,71" HREF="index.htm" ALT="Programming Perl"><AREA SHAPE="RECT" COORDS="467,0,514,18" HREF="jobjects/fsearch.htm" ALT="Search this book"></map><!-- TOP NAV BAR --><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch31_09.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="ch31_01.htm">Chapter 31: Pragmatic Modules</a></td><td align="right" valign="top" width="172"><a href="ch31_11.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h2 class="sect1">31.10. use filetest</h2><blockquote><pre class="programlisting">$can_perhaps_read = -r "file";      # use the mode bits{    use filetest 'access';          # intuit harder    $can_really_read = -r "file";}$can_perhaps_read = -r "file";      # use the mode bits again</pre></blockquote><p>This lexically scoped pragma tells the compiler to change the behavior ofthe unary file test operators <tt class="literal">-r</tt>, <tt class="literal">-w</tt>, <tt class="literal">-x</tt>, <tt class="literal">-R</tt>, <tt class="literal">-W</tt>, and <tt class="literal">-X</tt>,documented in <a href="ch03_01.htm">Chapter 3, "Unary and Binary Operators"</a>.  The default behavior for these filetests is to use the mode bits returned by the <tt class="literal">stat</tt> family of calls.However, this may not always be the right thing to do, such as when afilesystem understands ACLs (access control lists).  In environmentssuch as AFS where this matters, the <tt class="literal">use filetest</tt> pragma may help thepermission operators to return results more consistent with other tools.</p><p>There may be a slight performance decrease in the affected file testoperators under <tt class="literal">use filetest</tt>, since on some systems the extendedfunctionality needs to be emulated.</p><a name="INDEX-5423"></a><p>Warning: any notion of using file tests for security purposes is alost cause from the start.  There is a window open for race conditions,because there's no way to guarantee that the permissions will not changebetween the test and the real operation.  If you are the least bitserious about security, you won't use file test operators to decidewhether something <em class="emphasis">will</em> work.  Instead, just go ahead try the realoperation, then test for whether that operation succeeded.  (You shouldbe doing that anyway.) See the section "Handling Timing Glitches" in <a href="ch23_01.htm">Chapter 23, "Security"</a>.</p><h3 class="sect2">31.10.1. use filetest 'access'</h3><p>Currently only one import, <tt class="literal">access</tt>, is implemented.  Calling<tt class="literal">use filetext 'access'</tt> enables the use of <em class="emphasis">access</em>(2) or similarsyscalls when performing file tests, and <tt class="literal">no filetest 'access'</tt>similarly disables it.  This extended file test functionality isused only when the operator's operand (or, if you prefer, theunary function's argument) is a real filename, not when it is afilehandle.</p><!-- BOTTOM NAV BAR --><hr width="515" align="left"><div class="navbar"><table width="515" border="0"><tr><td align="left" valign="top" width="172"><a href="ch31_09.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0"></a></td><td align="right" valign="top" width="172"><a href="ch31_11.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">31.9. use fields</td><td align="center" valign="top" width="171"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0"></a></td><td align="right" valign="top" width="172">31.11. use integer</td></tr></table></div><hr width="515" align="left"><!-- LIBRARY NAV BAR --><img src="../gifs/smnavbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links"><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2001</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"> <area shape="rect" coords="2,-1,79,99" href="../index.htm"><area shape="rect" coords="84,1,157,108" href="../perlnut/index.htm"><area shape="rect" coords="162,2,248,125" href="../prog/index.htm"><area shape="rect" coords="253,2,326,130" href="../advprog/index.htm"><area shape="rect" coords="332,1,407,112" href="../cookbook/index.htm"><area shape="rect" coords="414,2,523,103" href="../sysadmin/index.htm"></map><!-- END OF BODY --></body></html>

⌨️ 快捷键说明

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