第二十七章,Perl 文化

本书是 Perl 文化的一部分,所以我们可不敢指望把我们所知道的所有与 Perl 文化有关的东西 都放在这里。我们只能用一点点历史和一点点艺术(有些人会说“极少艺术”)调起你的胃口。 更多 Perl 文化相关的东西,请访问 www.perl.org 和 www.perl.com。(Larry 把他自己 所有(正式)的疯话都放在了 www.wall.org/~larry。)或者你也可以从其他 Perl 程序员那里 打听。我们无法告诉你他们会是什么样的人——Perl 程序员唯一的共同特征可能就是他们都病态 地乐于助人。

27.1.时势造英雄

为了理解 Perl 为什么用现在这样的样子定义(或者为什么不定义成其他的样子),我们必须首先 明白为什么会有 Perl。所以,让我们先挖掘一下步满尘灰的历史书....

退回到 1986 年,Larry 是一个系统程序员,在做一个多层安全的广域网项目的开发。他负责 这么一个系统,这个系统由西海岸的三台 VAX 和三台 sun 机器,通过一条加密了的 1200 波特的串行线路和东海岸类似配置的系统连接组成的,因为 Larry 的主要工作是支持(他不是该 项目的程序员,只是系统专家),所以他就有机会利用他的三种优点(懒惰,不耐心,和狂傲)来 开发和提高所有有用的工具——比如 rn,patch,和 warp。(注:正是在这个时候,Larry 被 划入了“计算机动物”的范畴,这是以那些人的不可遏止的“再加一个特性”的渴望为基础 评判的,因为这种行为几乎成了生物必须。毕竟,如果生活就是太复杂的话,难道程序就不会吗? 尤其是想 rn 这样的程序,它真是应该当作一个高级的人工智能项目来看待,因为他们就可以为 你阅读新闻。当然,有些人已经在说 patch 程序太复杂了。)

一天,Larry 刚刚把 rn 撕成碎片,把它一片一片地放在他的目录里,大管理员就跑进来说, “Larry,我们需要一个管理配置,用它控制所有六台 VAX 和六台 sun。我们想在一个月里就要 它。你做一个吧!”

所以,从不逃避工作的 Larry,开始问自己做一个两个海岸的 CM 系统的最好的方法是什么,它 必须不用自己从头开始写,并且还可以查阅两个海岸的问题报告以及核准和控制。他想到的答案 只有一个词:B-news。(注:也就是 Usenet 传输软件的第二种实现。)

Larry 着手在这些机器上安装了新闻软件并且增加了两条控制命令:一条“append”命令用于向 现有的文章追加内容,和一条“synchronize”命令保持两个海岸的文章数目相同。CM 可以用 RCS (版本控制系统)做,而核准和控制可以用新闻和 rn 来做。到目前挺好。

然后大管理员让他生成报告。新闻是在核心机器里的一个独立的文件里维护的,里面有许多文件间 的交叉引用。Larry 的第一个反应是“用 awk。”糟糕的是,那个时候的 awk 无法做到以文件里 的信息为基础打开和关闭多个文件。Larry 不想编写一个特殊目的的工具。结果就是产生了一种 新的语言。

最初这种新的语言并不叫 Perl。Larry 和他的同事及亲友(Dan Faigin,写这段历史的人,和 Mark Biggar,他的妻弟,在初始设计阶段帮了大忙)交换了一大堆名字。实际上 Larry 考虑并 抛弃了字典里的所有三个或四个字母的单词。最早的名字是“Gloria”,以他的宝贝(和老婆) 命名。但他很快就发现这样会产生太多家庭混乱。

然后名字就成了“Pearl”,最后它变成了我们现在的“Perl”,部分原因是 Larry 看到另外 一种叫 PEARL 的语言的介绍,但最主要的原因是他懒得总要敲五个键。当然,这样 Perl 就可以 用做一个四字母的词。(不过,你会注意到,这里有以前首字缩写的残余: “Practical Extraction And Report Language”。)

最早的 Perl 没有今天的 Perl 那么多的特性。那时侯有模式匹配和文件句柄,有标量,有 格式化,但是很少有函数,没有相关的数组,而且只有一个实现得不怎么样的正则表达式,(从 rn 借来的)。手册页也只有 15 页。但是 Perl 比 sed 和 awk 快,并且开始在该项目的其他 应用里使用。

但是其他地方又开始需要 Larry 了。有一天另外一个大经理来了并且说:“Larry,给 R&D 做 支持。”并且 Larry 说,好吧。他带上 Perl 并且很快发现它逐渐成为系统管理的好工具。他 借来 Henry Spencer 漂亮的正则表达式软件包并且把它变成更有男人味(不过 Henry 可能不会 愿意在正餐的时候考虑这些特性。)然后 Larry 增加了大部分他想要的特性,以及一些别人 想要的特性。然后它就把 Perl 发布到网络上。(注:更让人吃惊的是,他先后工作于喷气推进 实验室(JPL),然后是 NetLabs? 和 Seagate 之后,仍然不断发布新 Perl。现在,其他人做了 大部分工作,而 Larry 假装为 O'Reilly & Associates(一个小公司,印刷关于计算机和相关 事物的小册子。)其余的就是历史了。(注:而这些东西,是历史的一个注解。当开始 Perl 的 工作的时候,Larry 已经把 rn 分解成碎片,并且准备做一次全面的重写。但因为他开始在 Perl 上干活,所以 Larry 没有再碰 rn。它仍然是碎片。有时候 Larry 说要用 Perl 重写 rn,但是 从来没当真。)

然后事情的发展就是这样的:Perl 1.0 在 1987 年十二月十八日发布;有些人仍然很认真地对待 Perl 的生日。Perl 2.0 在 1988 年六月发布,并且 Randal Schwartz 开始了“另外一个 Perl 黑客”的签名的传奇。在 1989 年,Tom Christiansen 在巴尔的摩 Usenix 拿出了 第一个公开的 Perl 教程。1989 年十月的 Perl 3.0开始,这门语言第一次以 GNU 公众版权 (GPL)发布和分发。

1990 年三月,Larry 写了第一首 Perl 小诗(见下一节)。然后他和 Randal 写了本书的 第一版,The Pink Camel;该书在 1991 年早期发行。然后 Perl 4.0 就立即发布了;除 GPL 之外,它还包括了 Artistic License(艺术版权)。

万众期待的 Perl 5 在 1994 年十月发布。这是一个完全重写的 Perl 版本,它包括对象和模块。 Perl 5 的到来甚至连 The Ecomomist 杂志都提到。到了 1995 年,正式向 Perl 社区引入 CPAN。在 1996 年,Jon Orwant 开始出版 The Perl Journal 杂志。在长时间的猜测之后, 本书的第二版,The Blue Camel,在那年的年末出版。第一次 O'Reilly Perl 大会(TPC) 1997 年夏季在加州 San Jose 举行。现在,重大时间几乎是每天都在发生,所以,关于历史的 其他部分,请检查 CPAST (Comprehensive Perl Arcana Society Tapestry (history.perl.org))上的 Perl 纪年表。

27.2 Perl 诗歌

在助手框里的诗歌的仿制品是在1990年的四月一日愚人节张贴到 Usenet 上的。我们不加注释的 把它放在这里,只是想表示典型的编程语言的隐喻真的是多么让人作呕。对所有有文学价值的东西 大概都是这样的吧。Larry 在最初为 Perl 3 写的那些“Black Perl”到了 Perl 5 不能分析 通过之后,真是感觉轻松许多。

不过,Larry 自己的文集很幸运地被 Perl 诗歌的王后,Sharon Hopkins 的光芒所掩盖。她 写了相当多的 Perl 诗歌,以及一些她在 1992 年 Usenet 冬季技术大会上拿出来的关于 Perl 诗歌的文章,标题是“Camels and Needles: Computer Poetry Meets the Perl Programming Language”。(这篇文章可以在 CAPN 的 misc/poetry.ps 找到。)除了是最多 产的 Perl 诗人之外,Sharon 还是下面这首诗歌的作者,这首诗是发表得最广泛的一首,并且 曾经在 Economist 和 Guardian 杂志上刊登:

    #!/usr/bin/perl

    APPEAL:

    listen (please, please);

    open yourself, wide;
        join (you, me),
    connect (us,together),

    tell me.

    do something if distressed;

        @dawn, dance;
        @evening, sing;
        read (books,$poems,stories) until peaceful;
        study if able;

        write me if-you-please;

    sort your feelings, reset goals, seek (friends, family, anyone);

            do*not*die (like this)
            if sin abounds;

    keys (hidden), open (locks, doors), tell secrets;
    do not, I-beg-you, close them, yet.

                                accept (yourself, changes),
                                bind (grief, despair);

    require truth, goodness if-you-will, each moment;

    select (always), length(of-days)

    # listen (a perl poem)
    # Sharon Hopkins
    # rev. June 19, 1995

Perl Poetry

    Article 970 of comp.lang.perl:
    Path: jpl-devvax!pl-dexxav!lwall
    From: lwall@jpl-dexxav.JPL.NASA.GOV (Larry Wall)
    Newsgroups: news.groups,rec.arts.poems,comp.lang.perl
    Subject: CALL FOR DISCUSSION: comp.lang.perl.poems
    Message-ID: <0401@jpl-devvax.JPL.NASA.GOV>
    Date: 1 Apr 90 00:00:00 GMT
    Reply-To: lwall@jpl-devvax.JPL.NSAS.GOV (Larry Wall)
    Organization: Jet Prepulsion Laboratory, Pasadena, CA
    Lines: 61

    It has come to my attention that there is a crying need for a place for people to express both their emotional 
    and technical natures simultaneously. Several people have sent me some items which don't fit into any 
    newsgroup. Perhaps it's because I recently posted to both comp.lang.perl and to rec.arts.poems, but people 
    seem to be writing poems in Perl, and they're asking me where they should post them. Here is a sampling:

    From a graduate student (in finals week), the following haiku:

    study, write, study,
    do review (each word) if time.
    close book. sleep? what's that?

    And someone writing from Fort Lauderdale writes:

    sleep, close together,
    sort of sin each spring & wait;
    50% die

    A person who wishes to remain anonymous wrote the following example of "Black Perl".  (The Pearl poet 
    would have been shocked, no doubt.)

    BEFOREHAND: close door, each window & exit;  wait until time.
        open spellbook, study, read (scan, select, tell us);
    write it, print the hex while each watches,
        reverse its length, write again;
        kill spiders, pop them, chop, split, kill them.
           unlink arms, shift, wait & listen (listening, wait),
    sort the flock (then, warn the "goats" & kill the "sheep");
        kill them, dump qualms, shift moralities,
        values aside, each one;
            die sheep! die to reverse the system
            you accept (reject, respect);
    next step,
        kill the next sacrifice, each sacrifice,
        wait, redo ritual until "all the spirits are pleased";
        do it ("as they say").
    do it(*everyone***must***participate***in***forbidden**s*e*x*).
    return last victim; package body;
        exit crypt (time, times & "half a time") & close it,
        select (quickly) & warn your next victim;
    AFTERWORDS: tell nobody.
        wait, wait until time;
        wait until next year, next decade;
            sleep, sleep, die yourself,
            die at last

    I tried that, and it actually parses in Perl.  It doesn't appear to do anything useful, however.  I think I'm glad, 
    actually... I hereby propose the creation of comp.lang.perl.poems as a place for such items, so we don't clutter 
    the perl or poems newsgroups with things that may be of interest to neither.  Or, alternately, we should 
    create rec.arts.poems.perl for items such as those above which merely parse, and don't do anything useful.  
    (There is precedent in rec.arts.poems, after all.)  Then also create comp.lang.perl.poems for poems that 
    actually do something, such as this haiku of my own:

    print STDOUT q
    Just another Perl hacker,
    unless $spring

    Larry Wall            lwall@jpl-devvax.jpl.nasa.gov


to top