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

📄 ch1.htm

📁 《Perl 5 Unreleased》
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<HTML>



<HEAD>

   <TITLE>Chapter 1 -- What is Perl?</TITLE>

   <META NAME="GENERATOR" CONTENT="Mozilla/3.0b5aGold (WinNT; I) [Netscape]">

</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">

<H1><FONT COLOR=#FF0000>Chapter 1</FONT></H1>

<H1><B><FONT SIZE=5 COLOR=#FF0000>What is Perl?</FONT></B>

</H1>

<P>

<HR WIDTH="100%"></P>

<P>

<H3 ALIGN=CENTER><FONT COLOR="#000000"><FONT SIZE=+2>CONTENTS<A NAME="CONTENTS"></A>

</FONT></FONT></H3>

<UL>

<LI><A HREF="#WhyPerl" >Why Perl?</A>

<LI><A HREF="#ABriefHistoryofPerl" >A Brief History of Perl</A>

<LI><A HREF="#TheBenefitsofUsingPerl" >The Benefits of Using Perl</A>

<UL>

<LI><A HREF="#CostandLicensing" >Cost and Licensing</A>

<LI><A HREF="#Availability" >Availability</A>

<LI><A HREF="#InterpretedLanguage1" >Interpreted Language</A>

<LI><A HREF="#Practical" >Practical</A>

<LI><A HREF="#LanguageCapabilities" >Language Capabilities</A>

<LI><A HREF="#IntegrationwithC" >Integration with C</A>

<LI><A HREF="#SpecializedExtensionstoPerl" >Specialized Extensions to Perl</A>

<LI><A HREF="#SocketCapability" >Socket Capability</A>

<LI><A HREF="#PerlIsRelativelyEasytoLearn" >Perl Is Relatively Easy to Learn</A>

<LI><A HREF="#PerlHasBuiltInDebuggingFacilities" >Perl Has Built-In Debugging Facilities</A>

<LI><A HREF="#PerlHelpIsReadilyAvailable" >Perl Help Is Readily Available</A>

<LI><A HREF="#PerlExamplesAreReadilyAvailable" >Perl Examples Are Readily Available</A>

</UL>

<LI><A HREF="#WhatAretheNegativesofUsingPerl" >What Are the Negatives of Using Perl?</A>

<UL>

<LI><A HREF="#InterpretedLanguage" >Interpreted Language</A>

<LI><A HREF="#PerceivedasPublicDomain" >Perceived as Public Domain</A>

<LI><A HREF="#InformalSupport" >Informal Support</A>

<LI><A HREF="#ProtectingProprietaryCode" >Protecting Proprietary Code</A>

<LI><A HREF="#ConcernsAboutReliability" >Concerns About Reliability</A>

<LI><A HREF="#MaintainabilityofScripts" >Maintainability of Scripts</A>

<LI><A HREF="#GNUCopyleftLicenseAgreement" >GNU Copyleft License Agreement</A>

</UL>

<LI><A HREF="#WhatCanPerlDo" >What Can Perl Do?</A>

<UL>

<LI><A HREF="#UNIXSystemMaintenance" >UNIX System Maintenance</A>

<LI><A HREF="#CGIScripts" >CGI Scripts</A>

<LI><A HREF="#MailProcessing" >Mail Processing</A>

<LI><A HREF="#AutomatingWebSiteMaintenance" >Automating Web Site Maintenance</A>

<LI><A HREF="#AutomatingFileRetrieval" >Automating File Retrieval</A>

</UL>

<LI><A HREF="#IsPerlforYou" >Is Perl for You?</A>

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

</UL>

<HR>

<P>

Perl is an interpreted language optimized for scanning arbitrary

text files, extracting information from these files, and printing

reports based on that information. It is also a good language

for many system management tasks. The language is intended to

be practical-easy to use, efficient, and complete-rather than

beautiful-tiny, elegant, and minimal. Perl was written by Larry

Wall (<TT><FONT FACE="Courier">lwall@sems.com</FONT></TT>), with

the help of lots of other contributors.

<H2><A NAME="WhyPerl"><FONT SIZE=5 COLOR=#FF0000>Why Perl?</FONT></A>

</H2>

<P>

UNIX system administrators and application developers often have

to rely on several different languages to accomplish their tasks.

This means learning a number of different syntaxes and having

to write in multiple languages to accomplish a task. For example,

to process a file, a system administrator might have to write

a shell script using <TT><FONT FACE="Courier">sh</FONT></TT>,

process a file using <TT><FONT FACE="Courier">awk</FONT></TT>

or <TT><FONT FACE="Courier">grep</FONT></TT>, and edit the file

using <TT><FONT FACE="Courier">sed</FONT></TT>. For other uses,

the administrator may have to create a C program with its longer

create/compile/debug development cycle.

<P>

It would be better if the administrator could combine many of

these tasks into a simple language that is easy to write and develop,

and reasonably efficient and complete. Along comes Perl.

<P>

In a single language, Perl combines some of the best features

of C, <TT><FONT FACE="Courier">sed</FONT></TT>, <TT><FONT FACE="Courier">awk</FONT></TT>,

and <TT><FONT FACE="Courier">sh</FONT></TT>. People familiar with

these languages have little difficulty being productive in Perl.

Perl's expression syntax is very C-like. Perl uses sophisticated

pattern-matching techniques to scan large amounts of data very

quickly. Although optimized for scanning text, Perl can also deal

with binary data. If you have a problem on which you would ordinarily

use <TT><FONT FACE="Courier">sed</FONT></TT>, <TT><FONT FACE="Courier">awk</FONT></TT>,

or <TT><FONT FACE="Courier">sh</FONT></TT>, but it exceeds these

tools' capabilities or must run a little faster and you don't

want to write the program in a compiled language such as C, Perl

may be the language for you.

<H2><A NAME="ABriefHistoryofPerl"><FONT SIZE=5 COLOR=#FF0000>A

Brief History of Perl</FONT></A></H2>

<P>

It is helpful to your understanding of Perl to know a little bit

about why Perl was created and how it evolved.

<P>

Larry Wall developed Perl in 1986. He was a systems programmer

on a project that was developing multilevel, secure wide area

networks. Larry was in charge of an installation consisting of

three Vaxes and three Suns on the West Coast of the United States

connected over an encrypted serial line (1200 baud!) to a similar

configuration on the East Coast of the United States. Larry's

primary job was system support &quot;guru.&quot; During this stint,

he developed several useful UNIX tools such as <TT><FONT FACE="Courier">rn</FONT></TT>,

<TT><FONT FACE="Courier">patch</FONT></TT>, and <TT><FONT FACE="Courier">warp</FONT></TT>.

<P>

Perl was developed in response to a management requirement for

a configuration management and control system for all six Vaxes

and all six Suns. As with most management requests, Larry had

a month to develop this tool!

<P>

Larry considered the problem of a bicoastal configuration management

tool, without writing it from scratch. The tool would have to

be capable of viewing problem reports on both coasts with approvals

and control. His answer was B-news.

<P>

Larry installed B-news on three machines and added two control

commands. Configuration management was done using RCS, and approvals

and submissions were done using news and <TT><FONT FACE="Courier">rn</FONT></TT>.

<P>

However, managers always need one thing more. Larry's manager

asked him to produce reports. B-news was maintained in separate

files on a master machine, with lots of cross references between

files. Larry's first thought was to use <TT><FONT FACE="Courier">awk</FONT></TT>

to produce the reports. Unfortunately, <TT><FONT FACE="Courier">awk</FONT></TT>

fell a bit short. It couldn't handle opening and closing multiple

files based on information in the files. Larry didn't want to

code a special purpose tool just for this job, so a new language

was born.

<P>

The language wasn't originally called Perl. Larry, his coworkers,

friends, and family considered just about every three- and four-letter

word in existence. One of the earliest names was &quot;Gloria&quot;

(his wife's name), but this was replaced due to the confusion

it caused in his household. The name became &quot;Pearl,&quot;

which was changed into the present day &quot;Perl,&quot; partly

due to the existence of a graphics language called &quot;pearl,&quot;

but mostly because five letters was a bit much to type all the

time. You'll find a reference to the former five-letter version

in the entry for the acronym Practical Extraction and Report Language.

<P>

The early version of Perl lacked many of the features of today's

version. The language included the following :

<UL>

<LI><FONT COLOR=#000000>Pattern matching</FONT>

<LI><FONT COLOR=#000000>File handles</FONT>

<LI><FONT COLOR=#000000>Scalars</FONT>

<LI><FONT COLOR=#000000>Formats</FONT>

<LI><FONT COLOR=#000000>A crippled implementation of pattern matching

(from </FONT><TT><FONT FACE="Courier">rn</FONT></TT>)

</UL>

<P>

The manual page was only 15 pages long. But Perl was faster than

<TT><FONT FACE="Courier">sed</FONT></TT> and <TT><FONT FACE="Courier">awk</FONT></TT>

and began to be used on other aspects of the project.

<P>

Larry moved on to support research and development and took Perl

with him. Perl was becoming a good tool for system administration.

Larry borrowed Henry Spencer's regular expression package and

modified it for Perl. Then Larry added most of the goodies he

and other people wanted and released it on the Internet.

<P>

The current version (5+) of the language is a complete rewrite

from the previous versions. It provides the following additional

benefits:<P>

<CENTER>

<TABLE BORDER=1>

<TR VALIGN=TOP><TD WIDTH=205>Usability enhancements</TD><TD WIDTH=385>It is now possible to write much more readable Perl code. (How any C-like language can be called readable is still beyond me!)

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Simplified grammar</TD><TD WIDTH=385>The new <TT><FONT FACE="Courier">yacc</FONT></TT> grammar is one half the size of the old one. Many of the arbitrary grammar rules have been regularized. The number of reserved words has 

been cut by two-thirds. Despite this, nearly all old Perl scripts will continue to work the same.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Lexical scoping</TD><TD WIDTH=385>Perl variables may now be declared within a lexical scope.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Arbitrarily nested data structures</TD><TD WIDTH=385>Any scalar value, including any array element, may now contain a reference to any other variable or subroutine.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Modularity and reusability</TD><TD WIDTH=385>The Perl library is now defined in terms of modules that can be shared easily among various packages.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Object-oriented programming</TD><TD WIDTH=385>A package can function as a class. Dynamic multiple inheritance and virtual methods are supported in a straightforward manner and with very little new syntax. File handles may now 

be treated as objects.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Embeddability and Extensibility</TD><TD WIDTH=385>Perl may now be embedded easily in your C or C++ application and can either call or be called by your routines through a documented interface.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>POSIX compliant</TD><TD WIDTH=385>A major new module is the POSIX module, which provides access to all available POSIX routines and definitions via object classes, where appropriate.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Package constructors and destructors</TD><TD WIDTH=385>The new <TT><FONT FACE="Courier">BEGIN</FONT></TT> and <TT><FONT FACE="Courier">END</FONT></TT> blocks provide a means to capture control as a package is being compiled and 

after the program exits.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Multiple simultaneous

<BR>

 BM implementations

</TD><TD WIDTH=385>A Perl program may now access DBM, NDBM, SDBM, GDBM, and Berkeley DB files from the same script, simultaneously.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Subroutine definitions may be autoloaded</TD>

<TD WIDTH=385>The <TT><FONT FACE="Courier">AUTOLOAD</FONT></TT> mechanism enables you to define any arbitrary semantics for undefined subroutine calls.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=205>Regular expression enhancements</TD><TD WIDTH=385>You can now specify non-greedy quantifiers and performing grouping without creating a back reference.<BR>

You can write regular expressions with embedded white space and comments for readability. A consistent extensibility mechanism has been added that is upwardly compatible with all old, regular expressions.

</TD></TR>

</TABLE></CENTER>

<P>

<H2><A NAME="TheBenefitsofUsingPerl"><FONT SIZE=5 COLOR=#FF0000>The

Benefits of Using Perl</FONT></A></H2>

<P>

Perl has many advantages as a general-purpose scripting language.

 These benefits include its generous licensing (it's free), its

interpreted nature, the fact that Perl is available for most platforms,

and more. The following sections detail some of the benefits of

this excellent language.

<H3><A NAME="CostandLicensing">Cost and Licensing</A></H3>

<P>

First, Perl is generally available on most server platforms, including

the following:

<UL>

<LI><FONT COLOR=#000000>Most UNIX variants</FONT>

<LI><FONT COLOR=#000000>MS-DOS</FONT>

<LI><FONT COLOR=#000000>Windows NT</FONT>

<LI><FONT COLOR=#000000>Windows 95</FONT>

<LI><FONT COLOR=#000000>OS/2</FONT>

<LI><FONT COLOR=#000000>Macintosh</FONT>

</UL>

<P>

Perl also has the distinct advantage of being &quot;low cost.&quot;

It is distributed free of charge or, at most, for a small copying

charge. Actually, Perl is distributed under the GNU &quot;copyleft,&quot;

which means that if you can execute Perl on your system, you should

have access to the source of Perl for no additional charge. (Actually,

a small copying charge might be imposed.) Perl may also be distributed

under the &quot;artistic license,&quot; which some people find

less threatening than the copyleft.

<H3><A NAME="Availability">Availability</A></H3>

<P>

Perl is readily available from many sources, including any <TT><FONT FACE="Courier">comp.sources.unix</FONT></TT>

archive or CPAN site. If you don't have Perl on your server or

development machine, it is easy to obtain either as source code

or precompiled binaries for many platforms. For those not on the

Internet, Perl is available via anonymous Uucp from both <TT><FONT FACE="Courier">uunet</FONT></TT>

and <TT><FONT FACE="Courier">osu-cis</FONT></TT>. Perl is often

⌨️ 快捷键说明

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