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

📄 appb_20.htm

📁 by Randal L. Schwartz and Tom Phoenix ISBN 0-596-00132-0 Third Edition, published July 2001. (See
💻 HTM
字号:
<html><head><title>References (Learning Perl, 3rd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Randal L. Schwartz and Tom Phoenix" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly &amp; Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596001320L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Learning Perl, 3rd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Learning Perl, 3rd Edition" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="appb_19.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"></a></td><td align="right" valign="top" width="228"><a href="appb_21.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">B.20. References</h2><p>Perl's<a name="INDEX-1289" />references aresimilar to C's <a name="INDEX-1290" />pointers, but in operation,they're more like what you have in Pascal or Ada. A reference"points" to a memory location, but because there'sno pointer arithmetic or direct memory allocation and deallocation,you can be sure that any reference you have is a valid one.References allow object-oriented programming and complex datastructures, among other nifty tricks. Seethe<a name="INDEX-1291" /> <em class="emphasis">perlreftut</em> and<em class="emphasis">perlref</em><a name="INDEX-1292" /> manpages.</p><a name="lperl3-APP-B-SECT-20.1" /><div class="sect2"><h3 class="sect2">B.20.1. Complex Data Structures</h3><p>References allow us to make <a name="INDEX-1293" /> <a name="INDEX-1294" />complex data structures in Perl. Forexample, suppose you want a two-dimensional array? You can dothat,<a href="#FOOTNOTE-416">[416]</a> or you can do something much moreinteresting, like have an array of hashes, a hash of hashes, or ahash of arrays of hashes.<a href="#FOOTNOTE-417">[417]</a> See the<em class="emphasis">perldsc</em><a name="INDEX-1295" /> (data-structures cookbook) and<em class="emphasis">perllol</em><a name="INDEX-1296" /> (lists of lists) manpages.</p><blockquote class="footnote"> <a name="FOOTNOTE-416" /><p>[416]Well, not really, but you can fake it so wellthat you'll hardly remember that there's adifference.</p> </blockquote><blockquote class="footnote"> <a name="FOOTNOTE-417" /><p>[417]Actually, you can'tmake any of these things; these are just verbal shorthands forwhat's really happening. What we call "an array ofarrays" in Perl is really an array of <em class="emphasis">references to</em>arrays. </p> </blockquote></div><a name="lperl3-APP-B-SECT-20.2" /><div class="sect2"><h3 class="sect2">B.20.2. Object-Oriented Programming</h3><p>Yes, Perl has objects; it's buzzword-compatible with all ofthose other languages. <a name="INDEX-1297" /> <a name="INDEX-1298" />Object-oriented(OO) programming lets you create your own user-defined datatypes withassociated abilities, using inheritance, overriding, and dynamicmethod lookup.<a href="#FOOTNOTE-418">[418]</a></p><blockquote class="footnote"> <a name="FOOTNOTE-418" /><p>[418]OO has its own set of jargon words. Infact, the terms used in any one OO language aren't even thesame ones that are typically used in another.</p> </blockquote><p>Unlike some object-oriented languages, though, Perl doesn'tforce you to use objects. (Even many object-oriented modules can beused without understanding objects.) But if your program is going tobe larger than N lines of code, it may be more efficient for theprogrammer (if a tiny bit slower at runtime) to make itobject-oriented. No one knows the precise value of N, but we estimateit's around a few thousand or so. See the<tt class="literal">perlobj</tt><a name="INDEX-1299" /> and<tt class="literal">perlboot</tt><a name="INDEX-1300" /> manpages for astart, and Damian Conway's excellent<a name="INDEX-1301" /><em class="citetitle">Object-OrientedPerl</em> (Manning Press) for more advanced information.</p></div><a name="lperl3-APP-B-SECT-20.3" /><div class="sect2"><h3 class="sect2">B.20.3. Anonymous Subroutines and Closures</h3><p>Odd as it may sound at first, it can be useful to have a<a name="INDEX-1302" /><a name="INDEX-1303" />subroutine without a name. Suchsubroutines can be passed as parameters to other subroutines, or theycan be accessed via arrays or hashes to make jump tables.</p><p><a name="INDEX-1304" />Closures are apowerful concept that comes to Perl from the world of Lisp. A closureis (roughly speaking) an anonymous subroutine with its own privatedata.</p></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="appb_19.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img alt="Home" border="0" src="../gifs/txthome.gif" /></a></td><td align="right" valign="top" width="228"><a href="appb_21.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr><tr><td align="left" valign="top" width="228">B.19. Syntax Extensions</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img alt="Book Index" border="0" src="../gifs/index.gif" /></a></td><td align="right" valign="top" width="228">B.21. Tied Variables</td></tr></table></div><hr width="684" align="left" /><img alt="Library Navigation Links" border="0" src="../gifs/navbar.gif" usemap="#library-map" /><p><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2002</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,85,94" href="../index.htm"><area shape="rect" coords="86,1,178,103" href="../lwp/index.htm"><area shape="rect" coords="180,0,265,103" href="../lperl/index.htm"><area shape="rect" coords="267,0,353,105" href="../perlnut/index.htm"><area shape="rect" coords="354,1,446,115" href="../prog/index.htm"><area shape="rect" coords="448,0,526,132" href="../tk/index.htm"><area shape="rect" coords="528,1,615,119" href="../cookbook/index.htm"><area shape="rect" coords="617,0,690,135" href="../pxml/index.htm"></map></body></html>

⌨️ 快捷键说明

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