The Perl Tutorial: What's Perl? (1)

来源:互联网 发布:广电网络集团 编辑:程序博客网 时间:2024/05/01 17:41

http://www.sitepoint.com/article/perl-tutorial-whats-perl

The Perl Tutorial: What's Perl? (Perl是什么?)

By Boris Mordkovich
March 15th 2001
Reader Rating: 8.1

Nov 24th 2004 yjgx007译

写在开始,为什么要译?
一是个人兴趣,加之我对Perl语言知之甚少,希望能够填补一下自已对Perl语言的空白,如果你与我一样,不妨先静心坐下,然后与我一起慢慢品味Perl语言。

Perl 是专为实际应用而生的简洁型语言,它是免费的语言,在 web 开发中,它用来做许多不同的事情,从写 CGI 脚本到帮助系统管理员维护它们的系统, Perl 由 Larry Wall (译注1)创建并一直维护它。在执行速度上它比编译型语言 C 要慢,但比解释型语言要快,在执行时它就已被编译然后解释执行。 Perl 编译器是存在的,但它仍然不够好,要了解更多 Perl 编译器的信息,请到 Perl 主页 .

Perl is short for Practical Extraction and Report Language. It's a language that is available free over the Web, and it's used for a variety of things, from writing CGI scripts to assisting administrators in maintaining their systems. Perl was created, and is still maintained, by Larry Wall. It's slower than C, but faster than a normal interpreted language. Instead, it's compiled when executed and then interpreted. A Perl compiler does exist but it's still under development. For more information on compiled Perl go to the Perl Home Page .

前面我已提到 Perl 是免费的,它在 GNU 许可下发布,并且源代码可以从 Perl 的主页上得到,这样,不用受太多的约束就可以定制 Perl 使其更灵活易用。 Perl 不依赖于平台限制,它能在许多不同平台上很好地工作,包括 Unix , Windows, 甚至是 Dos 下 . 而代码的修正度将依赖于任何一个系统的特定函数。

As I mentioned earlier, one of the nice things about Perl is that it's free. It's distributed under the GNU license, and the source is available from the Perl Home Page. This, along with the fact that it's flexible and has very few constraints, helps make Perl a popular language. It's also highly platform-independent, and has been ported to many different platforms including Unix , Windows, and even DOS. Code modifications can be minor or major depending on any system specific functions that are used.

事实上, Perl 的流行程度是很高的,你可以在许多地方找到相关的支持。推荐一个 Perl 的顶级站点: comp.lang.perl/#nlt#/Perl Newsgroup ,那里有许多的 Perl 专家在那里等着你。

Perl's popularity has also been encouraged by the fact that you can find support in a variety of places. At the top of the list is the comp.lang.perl/#nlt#/Perl Newsgroup , which is moderated by a number of Perl experts.


Perl and CGI (Perl和CGI)

这里简要解释一下 Perl 和 CGI 。如果你有过或想过建立自已的 web 站点,你就一定听说过 HTML, Javascript , Java 和 CGI 。 CGI 全称 Common Gateway Interface (公共网关接口)。 CGI 与 Javascript, HTML 和客户端 Java 不同, 在服务端,CGI提供了一套标准的方法:采用任何一个语言写作服务端程序,并与Web服务器软件一起完成对Web页面的应答和请求通讯 。换句话说, CGI是作为 web 站点的一部分与运行在服务器上的应用程序相结合的。

This is a brief explanation of Perl and CGI. If you have, or want to, put up your own web site, you'll have heard of HTML, Javascript , Java , and CGI. CGI stands for the Common Gateway Interface . CGI is unlike Javascript, HTML, and Client Side Java. CGI provides a standard method for programs written in any language to run on the server side, and to communicate with the Web server software in response to requests for Web pages. In other words, CGI is the part of your web site that communicates with the other programs running on your server.

写 CGI 程序或脚本的主要目的是为了给你的 web 站点提供更多的交互式效果。许多 web 站点是静态的,不允许用户交互,典型的交互类型有留言本,图片计数器,存放定单,访问数据库,其它应用程序访问等。

The main purpose of writing CGI programs or scripts is to afford more interactivity on your web site. Many web sites are static, and don't allow much user interaction. Others have guestbooks, image counters, and allow you to place orders, access databases, and other useful applications.

为了执行这些交互类型,你必须有一个运行在服务端的应用程序,例如,如何处理用户的各种输入,前面我已提及 CGI 脚本可以用任何一种语言来写作,但是更通用的是 Perl 和 C 。而 Perl 是写作 CGI 脚本的更好的语言,因为它具有强大的字符串处理能力。现在还有其它的语言,诸如 Java 和 PHP 同样具有这样的功能,但它们不采用 CGI 。

This is where CGI comes in. In order to implement these types of interactivity, you must have an application running on the server that, for example, knows how to process certain types of user input. As I mentioned, CGI scripts can be written in any language, but the most common are Perl and C. Perl is the preferred language for writing CGI scripts because of its strength in string manipulation. And now other programming languages such as Java and PHP are also gaining popularity, as they provide interactivity without the use of CGI.

CGI 程序仅仅是将某些特定的输入经过程序处理并输出(程序的写作不需要很严格)。当客户端用户在填写表单(一组 HTML 标记的集合,允许用户提交输入)并递交至服务端后,服务端会将表单的输入交由 CGI 程序处理并解析,并最终返回 HTML 代码以应答客户端用户的请求。

CGI programming is nothing more than programming with some special types of input, and a few very strict rules for program output. When a user fills out a FORM (a collection of HTML tags that allow them to submit input) the server sends the form input to the specified CGI program, which in turn parses the entered data and uses it in a specified manner, and returns HTML with an answer to the user's request.

当你选择一个用于写作 CGI 脚本的语言,应考虑这种语言应该具有下面的可选性:

  • 处理文本、字符串容易
  • 与其它软件库的接口
  • 访问操作系统环境变量

When you're choosing a language in which to write CGI scripts, ensure that the language you select:

· Makes text manipulation easy

· Is able to interface with other software utilities and libraries

· Is able to access your operating system's environment variables

Perl 确保上面的全部可选性都是必需的,使得 Perl 成为 CGI 程序语言的首选。如果你想写 CGI 脚本,我强烈建议你采用 Perl – 你将会发现那是多么的容易。如果你想获得更多有关 CGI 以及它是怎么工作的,可以在 NCSA site 找到 CGI 的详细说明(应该知道,这是一个针对有着丰富开发经验的程序员站点)。

Perl satisfies all the above requirements, making it a very good language for CGI programming. If you want to write your own CGI scripts, I'd suggest that you use Perl -- you'll find that it will make your life a lot easier. If you want to get more detail on CGI and how it works, try the CGI specification on the NCSA site (be aware, this is a pretty technical description aimed at experienced programmers).

译注1:

关于 Larry Wall

programmer , linguist , author , born March 10 , 1949 in Duncan , British Columbia , Canada , is most widely known for his creation of the Perl computer language in 1987 .

程序员,语言学家,作者,出生于1949年3月10日,出生地:加拿大卑斯省的邓肯市,众所周知的是它在1987年发明了Perl计算机语言。

Wall is the author of the rn Usenet software and the nearly universally used patch . He has won the IOCCC twice and was the recipient of the first Free Software Foundations award for the Advancement of Free Software in 1998.

Larry Wall写了rn - 一个用于Usenet新闻组的程序:对于软件开发, Rn是一种现在称为freesoftware或者opensource模型早期的原型----在其中各地的程序员通过网络互相协作,通过使得大家都可以获得代码来改进产品.。

Larry Wall还写了一个称为"patch"的小程序.Patch带有一个压缩的新的升级源代码并可以应用于以前的源代码.Patch能够提高旧代码更新的速度,并且甚至非常聪明地考虑以前的源代码作过的变化.

Larry Wall曾两次获得IOCCC 以及自由软件基金组织颁发给它的荣誉。

Beyond his technical skills, Wall is known for his wit and often ironic sense of humor, which he displays in the comments to his source code or on Usenet for example, "We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise").

Larry Wall is a trained linguist , which helped him with his book writing, as well as with the design of Perl. He is the co-author of Programming Perl (often referred to as the Camel Book ), which is the definitive resource for Perl programmers. He has edited the Perl Cookbook . His books were published by O'Reilly .

Wall continues to oversee further development of Perl and serves as the Benevolent Dictator for Life of the Perl project.

Larry Wall是Perl的创造者,也是其他一些流行的Unix自由软件的作者,包括rn新闻阅读器和无处不在的patch程序。从学历来看,Larry实际上是一位语言学家,是加州大学伯克利分校和洛杉矶分校的毕业生。在这些年中,他在Unisys、JPL、NetLabs和Seagate工作过,做的事情从离散事件模拟器到网络管理系统,偶尔还搞过宇宙飞船。正是在Unisys工作的期间,在他试图把一个跨东西海岸的配置管理系统用一个1200波特的加密链路、和一个经过修改的Netnews粘合起来时,Perl诞生了。Larry目前为O'Reilly公司工作。

Larry Wall 的个人主页: http://www.wall.org/~larry/

我的blog中收藏了一些有关Larry Wall的文章,非常不错:
传奇程序员Larry Wall:Perl的乐趣
Larry Wall 和 Perl的美德

原创粉丝点击