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

📄 ch02.htm

📁 Web_Programming_with_Perl5,一个不错的Perl语言教程。
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">



<HTML>







<HEAD>



<!-- This document was created from RTF source by rtftohtml version 3.0.1 -->







	<META NAME="GENERATOR" Content="Symantec Visual Page 1.0">



	<META HTTP-EQUIV="Content-Type" CONTENT="text/html;CHARSET=iso-8859-1">



	<TITLE>Without a title - Title</TITLE>



</HEAD>







<BODY BACKGROUND="r2harch.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/r2harch.gif" TEXT="#000000" BGCOLOR="#FFFFFF">







<H2 ALIGN="CENTER"><A HREF="ch01.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch01.htm"><IMG SRC="blanprev.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blanprev.gif" WIDTH="37" HEIGHT="37"



ALIGN="BOTTOM" BORDER="2"></A><A HREF="index-1.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/index-1.htm"><IMG SRC="blantoc.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blantoc.gif" WIDTH="42"



HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A><A HREF="ch03.htm" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/ch03.htm"><IMG SRC="blannext.gif" tppabs="http://210.32.137.15/ebook/Web%20Programming%20with%20Perl%205/blannext.gif"



WIDTH="45" HEIGHT="37" ALIGN="BOTTOM" BORDER="2"></A><BR>



<BR>



<FONT COLOR="#0000AA">2</FONT><BR>



<A NAME="Heading1"></A><FONT COLOR="#000077">A Perl5 Overview and Tutorial<BR>



</FONT>



<HR>



</H2>







<UL>



	<LI><A HREF="#Heading1">A Perl5 Overview and Tutorial</A>



	<UL>



		<LI><A HREF="#Heading4">New Features in Perl5</A>



		<UL>



			<LI><A HREF="#Heading5">Usability and Simplicity</A>



			<LI><A HREF="#Heading6">Lexical Scoping</A>



			<LI><A HREF="#Heading7">References</A>



			<LI><A HREF="#Heading8">Data Structures</A>



			<LI><A HREF="#Heading9">Modules and Libraries</A>



			<LI><A HREF="#Heading11">Reusability</A>



			<LI><A HREF="#Heading12">Object-Oriented Capabilities</A>



			<LI><A HREF="#Heading13">Extensible and Embeddable</A>



			<LI><A HREF="#Heading15">Souped-Up Regular Expressions</A>



			<LI><A HREF="#Heading16">Enhanced Safety and Security</A>



			<LI><A HREF="#Heading17">Other New Features in Perl5</A>



			<LI><A HREF="#Heading18">Summary of the New Perl5 Features</A>



		</UL>



		<LI><A HREF="#Heading19">Extended Perl5 Tutorial</A>



		<UL>



			<LI><A HREF="#Heading20">References</A>



			<LI><A HREF="#Heading22">An In-Depth Look at Perl5 Modules</A>



			<LI><A HREF="#Heading23">The Short History of Perl Extensions</A>



			<LI><A HREF="#Heading24">Modules and Extensions: Purpose and Design</A>



			<LI><A HREF="#Heading26">The Perl5 Module: Form and Function</A>



		</UL>



		<LI><A HREF="#Heading27">Listing 2.1. A simple extension module.</A>



		<LI><A HREF="#Heading29">Listing 2.2. Using the simple extension module.</A>



		<LI><A HREF="#Heading30">Listing 2.3. Using a blessed reference to invoke methods



		from the Foo module.</A>



		<LI><A HREF="#Heading31">Listing 2.4. The Customer module.</A>



		<LI><A HREF="#Heading32">Listing 2.5. Using the Customer module.</A>



		<UL>



			<LI><A HREF="#Heading33">Object-Oriented Techniques</A>



		</UL>



		<LI><A HREF="#Heading34">Listing 2.6. Subclassing the Customer module.</A>



		<LI><A HREF="#Heading36">Listing 2.7. Using the MyCust subclass.</A>



		<LI><A HREF="#Heading37">Listing 2.8. Overriding Customers methods.</A>



		<LI><A HREF="#Heading38">Listing 2.9. Using the overridden method in MyCust.</A>



		<LI><A HREF="#Heading39">Listing 2.10. Augmenting base class methods.</A>



		<UL>



			<LI><A HREF="#Heading41">Practical Issues for Using Modules: Downloading and Installation</A>



		</UL>



		<LI><A HREF="#Heading42">Traps for Perl4 Programmers Migrating to Perl5</A>



		<LI><A HREF="#Heading43">Summary</A>



	</UL>



</UL>







<P>



<HR>



</P>







<UL>



	<LI>New Features in Perl5



	<P>



	<LI>Extended Perl5 Tutorial



	<P>



	<LI>Traps for Perl4 Programmers Migrating to Perl5



</UL>







<P>The latest major version of Perl is Version 5, and because most or all the examples



in this book require it, I dedicate this chapter to trying to teach you a bit about



how it works and what's different about it, as compared to its predecessor, Perl4.</P>



<P>Perl5 is now into its third (and probably fourth, by the time this book is published)



public release. The early stages of development were fast-paced and difficult to



keep up with, but the specifications have settled, and most of the core functionality



has stabilized, both in its implementation details and in its usability.







<DL>



	<DT></DT>



</DL>







<H3 ALIGN="CENTER">



<HR WIDTH="84%">



<BR>



<FONT COLOR="#000077">NOTE:</FONT></H3>











<BLOCKQUOTE>



	<P>When I refer to the major version, I mean the first number in the version specifier--for



	example, the 5 in 5.002. The public release number, in this context, is 002. As of



	this writing, Perl is currently at revision number 5.003_05. The _05 delineates a



	development patch suite that postdates the official 5.003 release. The next public



	release, 5.004, will evolve from at least one additional development patch.<BR>



	



<HR>











</BLOCKQUOTE>







<P>In the following sections, I'll introduce you to the new features that are available



to the Perl programmer using Version 5. First, we'll take an extended look at some



of the more important Perl5 features, as they relate to this book. Next, I'll give



you a detailed explanation of reference variables, describing how they work, and



what they're used for. Then we'll take an in-depth look at modules and extensions



for Perl5. I'll describe how to use them, where to get them, and why you should use



them in the first place. Of course, you will need to use various modules extensively



throughout this book, in most or all of the examples. There are, however, other,



more fundamental reasons for using modules, and I'll emphasize these throughout the



book



<H3 ALIGN="CENTER">



<HR WIDTH="83%">



<BR>



<FONT COLOR="#000077">NOTE:</FONT></H3>











<BLOCKQUOTE>



	<P>I provide for you, on the accompanying CD-ROM, the latest version of the modules



	used in this book, as of the date of the assembly of the materials on the CD-ROM.



	You'll need to update them as new versions are released. You can find more details



	on updating Perl modules and extensions later in this chapter. Also see the description



	of the CPAN, in Chapter 1.<BR>



	



<HR>











</BLOCKQUOTE>







<P>Towards the end of this chapter, I'll show how you can use object-oriented techniques



to implement your own customized functionality in your Perl programs that use modules



or extensions, with a minimal amount of additional code. Finally, I close the chapter



with a description of the &quot;traps&quot; to be wary of when you're using Perl5--for



example, things that worked one way with Perl4 and now work differently, or not at



all, with Perl5. Not too many of these traps exist, and they're documented, so don't



worry too much about them, especially if you're starting from scratch and don't need



to convert any Perl4 programs to Perl5.</P>



<P>I make some assumptions in this chapter and, as previously mentioned, in this



book. Namely, I must assume that you have used Perl and written programs in the Perl



language. You should be familiar with most or all the Perl4 data types, operators,



and syntax. Furthermore, I'm not going to try to introduce all of Perl5 here. That



is in the realm of a complete book or books, some of which have recently been released.



My primary goal in this chapter is that you gain the familiarity you need to understand



the examples given within this book, and that you know enough when you're finished



reading it to implement your own programs and Web functionality using the techniques



described.



<H3 ALIGN="CENTER"><A NAME="Heading4"></A><FONT COLOR="#000077">New Features in Perl5</FONT></H3>



<P>You can use a number of new features and enhancements with Perl5. Many of them



are utilized in the modules demonstrated in this book. In the following sections,



I provide a short overview of most of them.



<H4 ALIGN="CENTER"><A NAME="Heading5"></A><FONT COLOR="#000077">Usability and Simplicity</FONT></H4>



<P>Some major improvements have been made to Perl, in terms of the layman's ability



to use it and understand it. While it's always been a tool for the common man, its



latest release has seen major work towards making it even easier to use and understand.



Let's see how this was accomplished. <B><TT>Enhanced Documentation</TT></B> Probably



the most significant improvement to the Perl distribution, outside of Perl itself,



is the documentation. The single monolithic manual page has been split up into logical



sections corresponding to the various aspects of Perl programming, along with sections



related to the more advanced aspects of Perl, like embedding the Perl interpreter



in an external program, and other sections as well.







<DL>



	<DT></DT>



</DL>







<P><B><TT>A Simple Convention</TT></B>











<BLOCKQUOTE>



	<P>As you read through this and other chapters, you'll notice the capitalized references



	to the various sections of the new manual, of the form PERLBLAH, where the BLAH corresponds



	to the section of the new Perl manual that is being referred to. Such references



	are there to help you find your way to the related sections of the Perl manual, regarding



	the current subject matter.







</BLOCKQUOTE>







<P>The Perl manual now has a total of 32 standard sections, each with a specific



intent. Table 2.1 lists them all. <BR>



<BR>



Table 2.1. Standard Perl manual sections<TT>.<BR>



<BR>



</TT>



<TABLE BORDER="0">



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERL</TD>



		<TD ALIGN="LEFT">Perl overview</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLTOC</TD>



		<TD ALIGN="LEFT">Perl documentation table of contents</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLDATA</TD>



		<TD ALIGN="LEFT">Perl data structures</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLSYN</TD>



		<TD ALIGN="LEFT">Perl syntax</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLOP</TD>



		<TD ALIGN="LEFT">Perl operators and precedence</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLRE</TD>



		<TD ALIGN="LEFT">Perl regular expressions</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLRUN</TD>



		<TD ALIGN="LEFT">Perl execution and options</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLFUNC</TD>



		<TD ALIGN="LEFT">Perl built-in functions</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLVAR</TD>



		<TD ALIGN="LEFT">Perl predefined variables</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLSUB</TD>



		<TD ALIGN="LEFT">Perl subroutines</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLMOD</TD>



		<TD ALIGN="LEFT">Perl modules</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLFORM</TD>



		<TD ALIGN="LEFT">Formats, and using write()</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLREF</TD>



		<TD ALIGN="LEFT">Perl references</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



		<TD WIDTH="97" ALIGN="LEFT">PERLDSC</TD>



		<TD ALIGN="LEFT">Perl data structures intro</TD>



	</TR>



	<TR ALIGN="LEFT" rowspan="1">



⌨️ 快捷键说明

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