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

📄 ch1.htm

📁 美国Macmillan出版社编写的Perl教程《Perl CGI Web Pages for WINNT》
💻 HTM
📖 第 1 页 / 共 4 页
字号:
utility awk. Awk is used by UNIX programmers to manipulate structured

data and produce formatted reports. Awk's main power lies behind

the use of regular expressions, a syntax that is common to UNIX

utilities. Regular expressions are a powerful way to manipulate

text, and this power is harnessed by Perl. The gory details about

regular expressions in Perl are dealt with in <A HREF="ch3.htm" tppabs="http://210.32.137.15/ebook/PC%20Magazine%20Programming%20Perl%205.0%20CGI%20Web%20Pages%20for%20Microsoft%20Windows%20NT/ch3.htm" >Chapter 3</A>

<P>

Perl was developed to help UNIX users with tasks that are too

heavy, or too portability-sensitive, for a shell. With UNIX, the

operating system is utilized through a shell, like the Bourne

or Korn shell. The shell provides an interface where the UNIX

user can run applications, rename files, and perform various housekeeping

tasks. This is different from the Windows method of interfacing

that Microsoft has developed, and more like using DOS or MS-DOS.

<P>

In this instance you can compare using a UNIX shell to using MS-DOS.

Both appear on the screen in the form of a text-driven terminal

screen and both operate from the command line. Often software

used by Windows is set up using MS-DOS first to extract and install

the various files involved. The commands available to you in MS-DOS

to perform tasks beyond this are fairly limited. For a larger

job, like automating a login sequence, you have to use a short

program, sometimes called a script.

<P>

Instead of creating an entire specialized program using a high-level

language like C, you might want to write a simple script using

a mid-level, or scripting, language. A simple comparison will

illustrate the difference between the two languages.

<P>

Listing 1.1 is a script in C to replace all the occurrences of

the letter &quot;o&quot; in a string[]:

<HR>

<BLOCKQUOTE>

<B>Listing 1.1 Example of a Script in C<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

#include &lt;memory.h&gt;

#include &lt;string.h&gt;

#include &lt;stdio.h&gt;

int  ch = 'o';

int  newch = 'p';

char string[] = &quot;The quick brown dog jumps over the lazy fox&quot;;

void main()

{

    char *pdest;

    int result;

    printf( &quot;String to be searched:\n\t\t%s\n&quot;, string );

    printf( &quot;Search char:\t%c\n&quot;, ch );

    printf( &quot;Replace with char:\t%c\n&quot;, newch );

    pdest = strchr( string, ch );

    while ( pdest != NULL ) 

    {

        result = pdest - string + 1;

        printf( &quot;Result:\t\t%c found at position %d\n\n&quot;, ch, result );

        string[result]=newch;

        pdest = strchr( string, ch );

    }

    printf( &quot;The new String:\n\t\t%s\n&quot;, string );

}

</PRE>

</BLOCKQUOTE>

<HR>

<P>

Listing 1.2 is the comparable script in Perl. It is obvious-even

to the inexperienced programmer-which language is easier to use

when handling text at this level.

<P>

In the UNIX world, Perl was created as just such a language. Its

purpose was to handle these mid-level jobs that would be too much

for the shell, and too little to justify using C.

<P>

This is not to imply that MS-DOS is exactly like a UNIX shell.

There are several major differences between them, the biggest

of which is how they differ in the method by which they handle

the resources available to the computer. This comparison of the

two terminal windows is only meant on the conceptual level, and

using a UNIX shell is very similar in experience to using MS-DOS,

for those of you who have never worked with UNIX.

<HR>

<BLOCKQUOTE>

<B>Listing 1.2 Perl Script<BR>

</B>

</BLOCKQUOTE>

<BLOCKQUOTE>

<PRE>

#!/usr/bin/perl

$string = &quot;The quick brown dog jumps over the lazy fox&quot;;

$ch = 'o';

$newch = 'p';

print &quot;String to be searched:\n\t\t$string\n&quot;;

print &quot;Search Char: $ch\n&quot;;

print &quot;Replace with Char: $newch\n&quot;;

$string =~s/$ch/$newch/g;

print &quot;The new string:\n\t\t$string\n&quot;;

</PRE>

</BLOCKQUOTE>

<HR>

<P>

a UNIX shell is very similar in experience to using MS-DOS, for

those of you who have never worked with UNIX<BR>

<P>

<CENTER>

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

<TR VALIGN=TOP><TD><B>NOTE</B></TD></TR>

<TR VALIGN=TOP><TD>

<BLOCKQUOTE>

<I>A real examination of MS-DOS and UNIX is a little outside the scope of this book, but if you want to learn more about UNIX and UNIX shells, you can try these books published by O'Reilly &amp; Associates, Inc.: </I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<I>Grace Todino, John Stang, and Jerry Peek's Learning the UNIX Operating System </I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<I>Daniel Gilly's UNIX in a Nutshell: System V Edition</I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<I>Bill Rosenblatt's Learning the Korn Shell </I>

</BLOCKQUOTE>

<BLOCKQUOTE>

<I>Dale Dougherty's sed &amp; awk</I>

</BLOCKQUOTE>



</TD></TR>

</TABLE></CENTER>

<P>

<P>

The initial purpose of Perl has grown by leaps and bounds. Now

found among Perl's various applications is the ability for Perl

to act as a CGI language on an Internet or an intranet server

to help provide Web services and systems administration tools.

It is this application of Perl that interests us most in this

book.

<H3><A NAME="TheAdvantagesofPerl">

The Advantages of Perl</A></H3>

<P>

Perl creates a more succinct and clear way of doing many tasks

that C, or one of the UNIX shells, does, but without a lot of

fuss. Unlike a compiled language like C or C++, Perl is an interpreted

script language. One of the things that means is that it has a

much shorter development cycle. 

<P>

Perl is also flexible. It runs on many different server setups

without needing much, if any, reconfiguration. Perl is available

for the Sun OS, AIX, Windows NT (WinPerl), and even Macintosh

platforms.

<P>

Perl, especially where CGI is concerned, is extremely portable.

If you want to use a script on a different operating system, you

just pack up your Perl file and bring it along. Think about Perl

scripts as though they were Lego blocks, and consider how you

can use different blocks that have their own function to build

new structures, then take them apart to build something different.

Not only can you develop Perl libraries to assist you in creating

more complex scripts, but you can also bring your work home with

you. Those of you in the freelance world are quite familiar with

the pressure placed on you to solve problems quickly. Perl lets

you develop a very efficient bag of tricks that you can take from

project to project that will let you spend more of your time solving

the problem instead of hammering out unique scripts each and every

time.

<P>

Perl is a language that is easy to read. The commands in a Perl

script are much more accessible than many other languages, usually

because other older languages have kept archaic and mystical aspects

that just confuse most people.

<P>

Perl is also quite powerful because it combines the versatility

and efficiency of a shell language with the ability to make low-level

system calls that you would expect from a C program. Perl can

work with many different text search tools, such as WAIS or Glimpse,

relational databases, such as Sybase and Oracle, and object-relational

packages like Illustra. This is a point that no Web programmer

should ever forget when dealing with the many different executables

on the market. Though your software ranges in its standards and

preferences, Perl can work with each one of them. Perl functions

on a level below a programmable &quot;layer&quot; between the

user and an information source, like a text file.

<P>

It must be stated though that not all of your CGI problems will

be solved with Perl. Often, a combination of CGI languages is

needed to overcome bug hurdles. There are no hard and fast programming

rules with CGI, so a clear understanding of the client-server

cycle, and its related protocols, should be taken to heart.

<P>

While Perl was originally designed with the UNIX operating system

in mind, there are now several other UNIX-like operating systems

that can handle it, Windows NT being one of them.

<H3><A NAME="LocatingPerl">

Locating Perl</A></H3>

<P>

For being such a relatively new programming language, Perl has

a very active programming community behind it. In fact, it's hard

to find someone who has anything bad to say about this language.

There are many sites on the World Wide Web that have Perl FAQ

lists, archives, and script libraries. Some of the more popular

of these are listed below:

<UL>

<LI><I><A HREF="javascript:if(confirm('http://www.inxpress.net/~moewes/comput  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.inxpress.net/%7Emoewes/comput'" tppabs="http://www.inxpress.net/%7Emoewes/comput">http://www.inxpress.net/~moewes/comput</A></I>-Perl for Windows

NT

<LI><I><A HREF="javascript:if(confirm('http://www.bhs.com/cgi-shl/dbml.exe?template=/BHS/winnt  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.bhs.com/cgi-shl/dbml.exe?template=/BHS/winnt'" tppabs="http://www.bhs.com/cgi-shl/dbml.exe?template=/BHS/winnt">http://www.bhs.com/cgi-shl/dbml.exe?template=/BHS/winnt</A></I>-Beverly

Hills Software Windows NT Resource Center

<LI><I><A HREF="javascript:if(confirm('http://www.bio.cam.ac.uk/cgi-lib/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.bio.cam.ac.uk/cgi-lib/'" tppabs="http://www.bio.cam.ac.uk/cgi-lib/">http://www.bio.cam.ac.uk/cgi-lib/</A></I>-The cgi-lib.pl Home

Page

<LI><I><A HREF="javascript:if(confirm('http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/'" tppabs="http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/">http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/</A></I>-libwww-perl

Mailing List Archives

<LI><I><A HREF="javascript:if(confirm('http://www.worldwidemart.com/scripts/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.worldwidemart.com/scripts/'" tppabs="http://www.worldwidemart.com/scripts/">http://www.worldwidemart.com/scripts/</A></I>-Matt's Script

Archive

<LI><I><A HREF="javascript:if(confirm('http://www.oac.uci.edu/indiv/ehood/perlWWW/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.oac.uci.edu/indiv/ehood/perlWWW/'" tppabs="http://www.oac.uci.edu/indiv/ehood/perlWWW/">http://www.oac.uci.edu/indiv/ehood/perlWWW/</A></I>-Another

good Perl archive of Perl scripts relating to the Web

</UL>

<P>

For Windows NT you need to use a version of Perl that has been

ported to the Windows NT environment. You will probably want to

install Perl on any workstations connected to your server locally

(in a LAN or WAN configuration) so that you can utilize Perl on

your own network as well.

<P>

On the Web you can find Perl for Windows NT (and lots of other

NT goodies) at <A HREF="javascript:if(confirm('http://www.perl.hip.com/.  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.perl.hip.com/.'" tppabs="http://www.perl.hip.com/.">http://www.perl.hip.com/.

</A><P>

This is the primary place to learn about all Windows NT Perl 5.001

concerns. They also house two e-mail lists, revolving around Windows

NT Perl 5.001, that can be subscribed to by going to the above

URL and registering. You can also join by sending an e-mail message

⌨️ 快捷键说明

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