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

📄 ch1.htm

📁 《Perl 5 Unreleased》
💻 HTM
📖 第 1 页 / 共 3 页
字号:
distributed with CD collections of utilities for UNIX platforms.

(See appendix B, "Perl Module Archives," for information

on Perl archives.)

<H3><A NAME="InterpretedLanguage1">Interpreted Language</A></H3>

<P>

Perl is interpreted. This can be either an advantage or disadvantage,

depending on your needs. For example, Perl has a short development

cycle compared to compiled languages, but it will never execute

as fast as a compiled language. I discuss the disadvantages in

the section called, &quot;What Are the Negatives of Using Perl?,&quot;

but there are some definite advantages.

<P>

One advantage of an interpreted language for tool or application

development is that you can perform incremental, iterative development

and testing without having to go through a create/compile/test/debug/fix

cycle. By eliminating the compile portion of the cycle, interpreted

languages can speed the development cycle drastically. It can

also be helpful if you are evolving your application by implementing

it with minimal capabilities and adding advanced capabilities

later.

<P>

Because it is interpreted and relatively C-like, you can also

use Perl as a <I>prototyping</I> language. This can be especially

useful with complex or technically difficult projects such as

network communication. You can use Perl's shortened development

cycle to evaluate your design and then, once it is proven, rewrite

the code in the language of your choice. By the way, C and C++

are good choices because Perl is a lot like C and supports much

the same functionality.

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

<P>

Perl is written to be practical. This means that it is

<UL>

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

<LI><FONT COLOR=#000000>Easy to use</FONT>

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

</UL>

<P>

These design goals mean that Perl programs can generally accomplish

a goal that would otherwise take several other languages, require

complex programming, and take longer to process.

<P>

But for many of us, practicality goes beyond this. It means that

you can get things <I>done</I> in Perl. In fact, there are usually

several ways that Perl can accomplish the same task. It also means

that the programmer can concentrate on getting the task done rather

than dealing with the &quot;beauty&quot; of the language in which

he or she is working.

<H4>Complete</H4>

<P>

As mentioned before, Perl combines some of the best features of

several languages. Here's a list of these languages:<P>

<CENTER>

<TABLE BORDER=1>

<TR VALIGN=TOP><TD WIDTH=109><CENTER><TT><FONT FACE="Courier">grep/awk</FONT></TT></CENTER>

</TD><TD WIDTH=481>General pattern-matching languages for selecting elements from a file.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=109><CENTER><TT><FONT FACE="Courier">C</FONT></TT></CENTER>

</TD><TD WIDTH=481>A general-purpose compiled programming language. (Perl is written in C.)

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=109><CENTER><TT><FONT FACE="Courier">sh</FONT></TT></CENTER>

</TD><TD WIDTH=481>A control language generally used for running programs and scripts written in other languages.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=109><CENTER><TT><FONT FACE="Courier">sed</FONT></TT></CENTER>

</TD><TD WIDTH=481>A stream editor for processing text streams (STDIN/STDOUT).

</TD></TR>

</TABLE></CENTER>

<P>

<P>

These languages typically have been the tools used by UNIX administrators

to accomplish tasks. In fact, they are often touted as the reason

that UNIX is an excellent development platform. They are still

excellent tools for the purposes for which they were written.

<P>

However, if you have to deal with several languages, you also

have to deal with <I>learning</I> these languages. For instance,

a task to process a single text file might require the administrator

to write a shell script to run an <TT><FONT FACE="Courier">awk</FONT></TT>

program to select lines that are subsequently processed by <TT><FONT FACE="Courier">sed</FONT></TT>.

<P>

<A HREF="f1-1.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/f1-1.gif" ><B>Figure 1.1:</B> <I>A single Perl script can often do the work of several other utilities.</I></A>

<P>

With Perl, the administrator or developer can accomplish his goals

in a single, easy-to-use language that performs the same tasks

as these languages.

<P>

With version 5.0 of Perl, the language also supports an object-oriented

approach to pro-gramming. This means that packages/modules can

be distributed as objects and used without knowledge of the underlying

code. These packages can also be extended as they can be in other

object-oriented languages. The key is that programmers only use

the object-oriented features of Perl if they need them for the

particular program they are writing.

<H4>Easy to Use</H4>

<P>

Above all, Perl is a language in which you can <I>do</I> things.

There are usually several ways to accomplish the same task. Although

some techniques are more efficient with system resources than

others, users can generally select the technique that is easier

for them to use (and maintain/enhance in the future) and go with

it.

<P>

The ease of use and completeness make Perl appropriate for quick-and-dirty,

one-time utilities as well as structured, complex applications.

<H4>Efficient</H4>

<P>

Perl is a straight-line language, which means that simple programs

do not have to deal with complex formatting or function/procedure

or object/method structures to accomplish their task. As a simple

example, let's pay homage to programming texts (including this

one) with the &quot;Hello World!&quot; program. Here it is in

C:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">void main()<BR>

{<BR>

&nbsp;&nbsp;&nbsp;&nbsp;printf(&quot;Hello World!&quot;);<BR>

}</FONT></TT>

</BLOCKQUOTE>

<P>

And here it is in Perl:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">print 'Hello World!'</FONT></TT>

</BLOCKQUOTE>

<P>

Get in, get out, and get the job done.

<H3><A NAME="LanguageCapabilities">Language Capabilities</A></H3>

<P>

Perl is <I>optimized</I> for text processing and, therefore, is

very efficient at many tasks required of system administrators

and application developers. Many of the files used in UNIX systems

administration are plain text files. Selecting records, processing

the selected records, and reporting exceptions are the heart of

many tasks performed in UNIX administration.

<P>

In the current versions of Perl, the language also includes much

additional functionality, making it appropriate for tasks such

as processing socket calls, embedding in programs written in C,

and maintaining POSIX-compliant systems.

<H3><A NAME="IntegrationwithC">Integration with C</A></H3>

<P>

Perl can access C libraries to take advantage of much of the code

written for this popular language. Utilities included with Perl

distributions enable you to convert the headers for these C libraries

into their Perl equivalents.

<P>

Perl 5.0 can be integrated easily into C and C++ applications.

Perl can call or be called by routines written in C or C++. The

Perl interface is through a set of <TT><FONT FACE="Courier">perl_call_*</FONT></TT>

functions. The call to C libraries is through the XS language

interface.

<H3><A NAME="SpecializedExtensionstoPerl">Specialized Extensions

to Perl</A></H3>

<P>

There are many specialized extensions to Perl, primarily for handling

specific databases such as Oracle, Ingres, Informix. These combine

the strengths of the Perl language with the access to the host

database.

<P>

At the time of this writing, <TT><FONT FACE="Courier">ftp.demon.co.uk</FONT></TT>

(<TT><FONT FACE="Courier">158.152.1.69</FONT></TT>) is the official

repository for database <TT><FONT FACE="Courier">&lt;foo&gt;perls</FONT></TT>

(see the following list), which can be found in <TT><FONT FACE="Courier">/pub/perl/db/perl4/</FONT></TT>.

It's mirrored at <TT><FONT FACE="Courier">ftp.cis.ufl.edu</FONT></TT>

(<TT><FONT FACE="Courier">198.17.47.33</FONT></TT>) in <TT><FONT FACE="Courier">/pub/perl/scripts/db/</FONT></TT>.

<P>

<CENTER>

<TABLE BORDER=1>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">btreeperl</FONT></TT>

</TD><TD WIDTH=186>NDBM extensions</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">ctreeperl</FONT></TT>

</TD><TD WIDTH=186>C-Tree extensions</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">duaperl</FONT></TT>

</TD><TD WIDTH=186>X.500 directory user agent</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">ingperl</FONT></TT>

</TD><TD WIDTH=186>Ingres</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">isqlperl</FONT></TT>

</TD><TD WIDTH=186>Informix</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">interperl</FONT></TT>

</TD><TD WIDTH=186>Interbase</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">oraperl</FONT></TT>

</TD><TD WIDTH=186>Oracle 6 and 7</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">pgperl</FONT></TT>

</TD><TD WIDTH=186>Postgres</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">sybperl</FONT></TT>

</TD><TD WIDTH=186>Sybase 4</TD></TR>

<TR VALIGN=TOP><TD WIDTH=151><TT><FONT FACE="Courier">uniperl</FONT></TT>

</TD><TD WIDTH=186>UNIFY 5.0</TD></TR>

</TABLE></CENTER>

<P>

<P>

See appendix B, &quot;Perl Module Archives,&quot; for more information

on these repositories.

<H3><A NAME="SocketCapability">Socket Capability</A></H3>

<P>

Perl has the capability to read/write TCP/IP sockets. This gives

it the capability to communicate with servers of all types that

rely on socket communication. It also enables you to write utility

and &quot;robot&quot; programs in the Perl language. For example,

Perl's socket capability can be used to write a robot program

to automate the checking of a World Wide Web (WWW) site to verify

the validity of links on your Web pages. This can be especially

useful in keeping a site up-to-date, given the volatility of the

Internet in its relative infancy.

<H3><A NAME="PerlIsRelativelyEasytoLearn">Perl Is Relatively Easy

to Learn</A></H3>

<P>

Unlike many programming languages, Perl is designed to be practical

rather than beautiful. By this I mean that Perl was designed from

the start to be easy to use, efficient, and complete rather than

tiny, elegant, and minimal.

<P>

Programming in Perl is relatively easy, especially if you have

experience in C or another C-like language. Like many scripting

languages, Perl reads its programs from the first line to the

last line. It doesn't require complex structures to be able to

create a program. It does, however, support subroutines or functions

and, in version 5.0, can be object oriented.

<H3><A NAME="PerlHasBuiltInDebuggingFacilities">Perl Has Built-In

Debugging Facilities</A></H3>

<P>

The Perl interpreter has a built-in debugger that can help reduce

the time it takes to debug applications. The debugger is activated

through the use of the <TT><FONT FACE="Courier">-d</FONT></TT>

switch on the command line. In addition, the <TT><FONT FACE="Courier">-w</FONT></TT>

switch provides a complete set of warnings that can be invaluable

in debugging Perl scripts.

<H3><A NAME="PerlHelpIsReadilyAvailable">Perl Help Is Readily

Available</A></H3>

<P>

Because Perl is very popular as a scripting language, there is

a lot of help out there. Newsgroup discussions are a good place

to start when you require help on Perl programming. There are

newsgroups devoted entirely to Perl and newsgroups devoted to

Web page creation in which the majority of the discussion is about

Perl. Here are some of them:<P>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR VALIGN=TOP><TD WIDTH=244><I>Newsgroup</I></TD><TD WIDTH=346><I>Comment</I>

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=244><TT><FONT FACE="Courier">comp.lang.perl...</FONT></TT>

</TD><TD WIDTH=346>This set of newsgroups covers information about Perl in general. Much of the discussion in the specific groups covers using Perl for utility purposes and also as a CGI scripting language.

</TD></TR>

<TR VALIGN=TOP><TD WIDTH=244><TT><FONT FACE="Courier">comp.lang.perl.announce</FONT></TT>

</TD><TD WIDTH=346>Provides information about new modules for Perl programming.

⌨️ 快捷键说明

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