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

📄 ch30_01.htm

📁 编程珍珠,里面很多好用的代码,大家可以参考学习呵呵,
💻 HTM
字号:
<html><head><title>The Standard Perl Library (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="The Standard Perl Library"><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="ch29_02.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0"></a></td><td align="center" valign="top" width="171"><a href="part5.htm">Part 5: Reference Material</a></td><td align="right" valign="top" width="172"><a href="ch30_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr></table></div><hr width="515" align="left"><!-- SECTION BODY --><h1 class="chapter">Chapter 30.  The Standard Perl Library</h1><div class="htmltoc"><h4 class="tochead">Contents:</h4><p><a href="ch30_01.htm">Library Science</a><br><a href="ch30_02.htm">A Tour of the Perl Library</a><br></p></div><p>The standard Perl distribution contains much more than just the <em class="emphasis">perl</em> executable that executes your scripts.  It also includes hundreds of modules filled with reusable code.  Because thestandard modules are available everywhere, if you use one of them inyour program, you can run your program anywhere Perl is installed, without any extra installation steps.</p><h2 class="sect1">30.1. Library Science</h2><p>Before we enumerate these modules in the following chapters, let'sreview a bit of the terminology we've been splattering about.</p><dl><dt><b><em class="emphasis">namespace</em></b></dt><dd><p>A <em class="emphasis">namespace</em> is a place to keep names so they won't be confused withnames in other namespaces.  This leaves you with the simpler problem ofnot confusing the namespaces themselves.  There are two ways to avoidconfusing namespaces with each other: give them unique names, or givethem unique locations.  Perl lets you do both: named namespaces arecalled packages and unnamed namespaces are called lexical scopes. Sincelexical scopes can be no larger than a file, and since thestandard modules are file-sized (at minimum), it follows that allmodule interfaces must make use of named namespaces (packages) ifthey're to be used by anyone outside the file.</p></dd><dt><b><em class="emphasis">package</em></b></dt><dd><p>A <em class="emphasis">package</em> is Perl's standard mechanism for declaring a namednamespace.  It's a simple mechanism for grouping together relatedfunctions and variables.  Just as two directories can both contain a(different) file named <em class="emphasis">fred</em>, two different parts of a Perl programcan each have its own <tt class="literal">$fred</tt> variable or <tt class="literal">&amp;fred</tt> function.  Eventhough these variables or functions seem to have the same name as oneanother, those names reside in distinct namespaces managed by the<tt class="literal">package</tt> declaration.  Package names are used to identify bothmodules and classes, as described in <a href="ch11_01.htm">Chapter 11, "Modules"</a>, and in<a href="ch12_01.htm">Chapter 12, "Objects"</a>.</p></dd><dt><b><em class="emphasis">library</em></b></dt><dd><p>The term <em class="emphasis">library</em> is unfortunately rather overloaded in Perlculture.  These days we normally use the term to mean the entire set ofPerl modules installed on your system.</p><p>Historically, a Perl library was also a single file containing acollection of subroutines sharing some common purpose.  Such a fileoften has the file extension <em class="emphasis">.pl</em>, short for "perl library".  Westill use that extension for random bits of Perl code that you pull inwith <tt class="literal">do</tt>&nbsp;<em class="replaceable">FILE</em> or with <tt class="literal">require</tt>.  Although it's not afull-fledged module, a library file typically declares itself to be ina distinct package so related variables and subroutines can be kepttogether and don't accidentally interfere with othervariables in your program.  There is no mandatory extension; othersbesides <em class="emphasis">.pl</em> sometimes occur as explained later in thischapter.  These simple,unstructured library files have been largely superseded by the module.</p></dd><dt><b><em class="emphasis">module</em></b></dt><dd><p>A Perl <em class="emphasis">module</em> is a library file that conforms tocertain specificconventions that allow one or more files implementing that module to bebrought in with a single <tt class="literal">use</tt> declaration at compiletime.  Modulefilenames must always end in <em class="emphasis">.pm</em>, because the<tt class="literal">use</tt> declaration assumesit.  The <tt class="literal">use</tt> declaration will also translate thepackage separator <tt class="literal">::</tt> to whateveryour directory separator is, so that the directory structure in yourPerl library can match your package structure.  <a href="ch11_01.htm">Chapter 11, "Modules"</a>describes how to create your own Perl modules.</p></dd><dt><b><em class="emphasis">class</em></b></dt><dd><p>A <em class="emphasis">class</em> is just a module that implements methodsfor objectsassociated with the module's package name.  If you're interested inobject-oriented modules, see <a href="ch12_01.htm">Chapter 12, "Objects"</a>.</p></dd><dt><b><em class="emphasis">pragma</em></b></dt><dd><p>A <em class="emphasis">pragma</em> is just a special module that twiddlesPerl's internal knobs. See <a href="ch31_01.htm">Chapter 31, "Pragmatic Modules"</a>.</p></dd><dt><b><em class="emphasis">extension</em></b></dt><dd><p>An <em class="emphasis">extension</em> is a Perl module that, in addition to loading a <em class="emphasis">.pm</em> file, also loads a shared library implementing the module's semantics in C or C++.</p></dd><dt><b><em class="emphasis">program</em></b></dt><dd><p>A Perl <em class="emphasis">program</em> is code designed to be run as an independent entity;also known as a <em class="emphasis">script</em> when you don't want anyone to expect muchfrom it, an <em class="emphasis">application</em> when it's big and complicated, an<em class="emphasis">executable</em> when its caller doesn't care what language it was writtenin, or an <em class="emphasis">enterprise solution</em> when it costs a fortune.  Perlprograms might exist as source code, bytecode, or native machine code. Ifit's something you might run from the command line, we'll call ita program.</p></dd></dl><!-- 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="ch29_02.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="ch30_02.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0"></a></td></tr><tr><td align="left" valign="top" width="172">29.2. Perl Functions in Alphabetical Order</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">30.2. A Tour of the Perl Library</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 + -