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

📄 ch18_07.htm

📁 编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,
💻 HTM
📖 第 1 页 / 共 2 页
字号:
during run time.  Once a <tt class="literal">BEGIN</tt> block has run, it is immediatelyundefined and any code it used is returned to Perl's memory pool.You couldn't call a <tt class="literal">BEGIN</tt> block as a subroutine even if you tried,because by the time it's there, it's already gone.</p><p><a name="INDEX-3314"></a>Similar to <tt class="literal">BEGIN</tt> blocks, <tt class="literal">INIT</tt>blocks are run just before the Perl run time begins execution, in"first in, first out" (FIFO) order.  For example, the code generatorsdocumented in <em class="emphasis">perlcc</em> make use of<tt class="literal">INIT</tt> blocks to initialize and resolve pointers toXSUBs. <tt class="literal">INIT</tt> blocks are really just like<tt class="literal">BEGIN</tt> blocks, except they let the programmerdistinguish construction that must happen at compile phase fromconstruction that must happen at run phase.  When you're running ascript directly, that's not terribly important because the compilergets invoked every time anyway; but when compilation is separate fromexecution, the distinction can be crucial.  The compiler may only beinvoked once, and the resulting executable may be invoked many times.</p><p>Similar to <tt class="literal">END</tt> blocks, <tt class="literal">CHECK</tt>blocks are run just after the Perl compile phase ends but before run phase begins, in LIFO order.  <tt class="literal">CHECK</tt> blocks areuseful for "winding down" the compiler just as <tt class="literal">END</tt>blocks are useful for winding down your program.  In particular, the backends all use <tt class="literal">CHECK</tt> blocks as the hook fromwhich to invoke their respective code generators.  All they need to dois put a <tt class="literal">CHECK</tt> block into their own module, and itwill run at the right time, so you don't have to install a<tt class="literal">CHECK</tt> into your program.  For this reason, you'llrarely write a <tt class="literal">CHECK</tt> block yourself, unless you'rewriting such a module.</p><p><a name="INDEX-3315"></a><a name="INDEX-3316"></a>Putting it all together, <a href="ch18_07.htm#perl3-tab-annotations">Table 18-1</a> lists various constructs with details onwhen they compile and when they run the code represented by "<tt class="literal">...</tt>".</p><a name="perl3-tab-annotations"></a><h4 class="objtitle">Table 18.1. What Happens When</h4><table border="1"><tr><th><p>Block</p></th><th><p>Compiles</p></th><th><p>Traps</p></th><th><p>Runs</p></th><th><p>Traps</p></th><th><p>Call</p></th></tr><tr><th><p>or</p></th><th><p>During</p></th><th><p>Compile</p></th><th><p>During</p></th><th><p>Run</p></th><th><p>Trigger</p></th></tr><tr><th><p>Expression</p></th><th><p>Phase</p></th><th><p>Errors</p></th><th><p>Phase</p></th><th><p>Errors</p></th><th><p>Policy</p></th></tr><tr><td><tt class="literal">use ...</tt></td><td>C</td><td>No</td><td>C</td><td>No</td><td>Now</td></tr><tr><td><tt class="literal">no ...</tt></td><td>C</td><td>No</td><td>C</td><td>No</td><td>Now</td></tr><tr><td><tt class="literal">BEGIN {...}</tt></td><td>C</td><td>No</td><td>C</td><td>No</td><td>Now</td></tr><tr><td><tt class="literal">CHECK {...}</tt></td><td>C</td><td>No</td><td>C</td><td>No</td><td>Late</td></tr><tr><td><tt class="literal">INIT {...}</tt></td><td>C</td><td>No</td><td>R</td><td>No</td><td>Early</td></tr><tr><td><tt class="literal">END {...}</tt></td><td>C</td><td>No</td><td>R</td><td>No</td><td>Late</td></tr><tr><td><tt class="literal">eval {...}</tt></td><td>C</td><td>No</td><td>R</td><td>Yes</td><td>Inline</td></tr><tr><td><tt class="literal">eval "..."</tt></td><td>R</td><td>Yes</td><td>R</td><td>Yes</td><td>Inline</td></tr><tr><td><tt class="literal">foo(...)</tt></td><td>C</td><td>No</td><td>R</td><td>No</td><td>Inline</td></tr><tr><td><tt class="literal">sub foo {...}</tt></td><td>C</td><td>No</td><td>R</td><td>No</td><td>Call anytime</td></tr><tr><td><tt class="literal">eval "sub {...}"</tt></td><td>R</td><td>Yes</td><td>R</td><td>No</td><td>Call later</td></tr><tr><td><tt class="literal">s/pat/.../e</tt></td><td>C</td><td>No</td><td>R</td><td>No</td><td>Inline</td></tr><tr><td><tt class="literal">s/pat/"..."/ee</tt></td><td>R</td><td>Yes</td><td>R</td><td>Yes</td><td>Inline</td></tr></table><p>Now that you know the score, we hope you'll be able to compose andperform your Perl pieces with greater confidence.</p><a name="INDEX-3317"></a><a name="INDEX-3318"></a><!-- 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="ch18_06.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="ch19_01.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">18.6. Code Development Tools</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">19. The Command-Line Interface</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 + -