📄 ch01_02.htm
字号:
<html><head><title>What Does "Perl" Stand For? (Learning Perl, 3rd Edition)</title><link rel="stylesheet" type="text/css" href="../style/style1.css" /><meta name="DC.Creator" content="Randal L. Schwartz and Tom Phoenix" /><meta name="DC.Format" content="text/xml" scheme="MIME" /><meta name="DC.Language" content="en-US" /><meta name="DC.Publisher" content="O'Reilly & Associates, Inc." /><meta name="DC.Source" scheme="ISBN" content="0596001320L" /><meta name="DC.Subject.Keyword" content="stuff" /><meta name="DC.Title" content="Learning Perl, 3rd Edition" /><meta name="DC.Type" content="Text.Monograph" /></head><body bgcolor="#ffffff"><img alt="Book Home" border="0" src="gifs/smbanner.gif" usemap="#banner-map" /><map name="banner-map"><area shape="rect" coords="1,-2,616,66" href="index.htm" alt="Learning Perl, 3rd Edition" /><area shape="rect" coords="629,-11,726,25" href="jobjects/fsearch.htm" alt="Search this book" /></map><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch01_01.htm"><img alt="Previous" border="0" src="../gifs/txtpreva.gif" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"></a></td><td align="right" valign="top" width="228"><a href="ch01_03.htm"><img alt="Next" border="0" src="../gifs/txtnexta.gif" /></a></td></tr></table></div><h2 class="sect1">1.2. What Does "Perl" Stand For?</h2><p><a name="INDEX-10" /> <a name="INDEX-11" />Perl is short for "<a name="INDEX-12" /> <a name="INDEX-13" />Practical Extraction andReport Language," although it has also been called a"Pathologically Eclectic Rubbish Lister," among otherexpansions.<a href="#FOOTNOTE-11">[11]</a> There's no point in arguing whichexpansion is correct, because both of those are endorsed by LarryWall, Perl's creator and chief architect, implementor, andmaintainer. He created Perl in the mid-1980s when he was trying toproduce some reports from a Usenet-news-like hierarchy of files for abug-reporting system, and <i class="command">awk</i> ran out of steam.Larry, being the lazy programmer that he is,<a href="#FOOTNOTE-12">[12]</a> decided to overkill the problem with ageneral-purpose tool that he could use in at least one other place.The result was Perl version zero.</p><blockquote class="footnote"> <a name="FOOTNOTE-11" /><p>[11]It's actually a retronym, not anacronym. That is, Larry came up with the name first, and theexpansion later. That's why "Perl" isn't inall caps.</p> </blockquote><blockquote class="footnote"><a name="FOOTNOTE-12" /><p>[12]We're not insulting Larry by saying he's lazy;laziness is a virtue. The wheelbarrow was invented by someone who wastoo lazy to carry things; writing was invented by someone who was toolazy to memorize; Perl was invented by someone who was too lazy toget the job done without inventing a whole new computerlanguage.</p> </blockquote><a name="lperl3-CHP-1-SECT-2.1" /><div class="sect2"><h3 class="sect2">1.2.1. Why Didn't Larry Just Use Some Other Language?</h3><p>There's no shortage of computer languages, is there? But, atthe time, Larry didn't see anything that really met his needs.If one of the other languages of today had been available back then,perhaps Larry would have used one of those. He needed something withthe quickness of coding available in shell or <i class="command">awk</i>programming, and with some of the power of more advanced tools like<i class="command">grep</i>, <i class="command">cut</i>,<i class="command">sort</i>, and <i class="command">sed</i>,<a href="#FOOTNOTE-13">[13]</a> without having to resort to a language like C.</p><blockquote class="footnote"><a name="FOOTNOTE-13" /><p>[13]Don't worry if you don't know what these are. Allthat matters is that they were the programs Larry had in his Unixtoolbox, but they weren't up to the tasks at hand.</p></blockquote><p>Perl tries to fill the gap between low-level<a name="INDEX-14" /> <a name="INDEX-15" /><a name="INDEX-16" />programming (such as in C or C++ orassembly) and high-level programming (such as "shell"programming). Low-level programming is usually hard to write andugly, but fast and unlimited; it's hard to beat the speed of awell-written low-level program on a given machine. And there'snot much you can't do there. High-level programming, at theother extreme, tends to be slow, hard, ugly, and limited; there aremany things you can't do at all with the shell, ifthere's no command on your system that provides the neededfunctionality. Perl is easy, nearly unlimited, mostly fast, and kindof ugly.</p><p>Let's take another look at those four claims we just made aboutPerl:</p><p>First, Perl is easy. As you'll see, though, this meansit's easy to <em class="emphasis">use</em>. It's notespecially easy to <em class="emphasis">learn</em>. If you drive a car,you spent many weeks or months learning that, and now it's easyto drive. When you've been programming Perl for about as manyhours as it took you to learn to drive, Perl will be easy foryou.<a href="#FOOTNOTE-14">[14]</a></p><blockquote class="footnote"> <a name="FOOTNOTE-14" /><p>[14]But we hope you'll crash less often withthe car.</p> </blockquote><p>Perl is nearly unlimited. There are very few things you can'tdo with Perl. You wouldn't want to write ainterrupt-microkernel-level device driver in Perl (even thoughthat's been done), but most things that ordinary folks needmost of the time are good tasks for Perl, from quick little one-offprograms to major industrial-strength applications.</p><p>Perl is mostly fast. That's because nobody is developing Perlwho doesn't also use it -- so we all want it to be fast. Ifsomeone wants to add a feature that would be really cool, but whichwould slow down other programs, Larry is almost certain to refuse thenew feature until we find a way to make it quick enough.</p><p>Perl is kind of ugly. This is true. The symbol of Perl has become thecamel, from the cover of the venerable <a name="INDEX-17" />Camel book (also known as<em class="citetitle">ProgrammingPerl</em><a name="INDEX-18" /> <a name="INDEX-19" />), a sister to this one. Camels are kindof ugly, too. But they work hard, even in tough conditions. Camelsare there to get the job done despite all difficulties, even whenthey look bad and smell worse and sometimes spit at you. Perl is alittle like that.</p></div><a name="lperl3-CHP-1-SECT-2.2" /><div class="sect2"><h3 class="sect2">1.2.2. Is Perl Easy or Hard?</h3><p>It's easy to use, but sometimes hard to learn. This is ageneralization, of course. But in designing Perl, Larry has had tomake many trade-offs. When he's had the chance to makesomething easier for the programmer at the expense of being moredifficult for the student, he's decided in theprogrammer's favor nearly every time. That's becauseyou'll learn Perl only once, but you'll use it again andagain.<a href="#FOOTNOTE-15">[15]</a></p><blockquote class="footnote"> <a name="FOOTNOTE-15" /><p>[15]If you're going to use a programminglanguage for only a few minutes each week or month, you'dprefer one that is easier to learn, since you'll have forgottennearly all of it from one use to the next. Perl is for people who areprogrammers for at least twenty minutes per day, and probably most ofthat in Perl.</p> </blockquote><p>Perl has any number of conveniences that let the programmer savetime. For example, most<a name="INDEX-20" /><a name="INDEX-21" />functions will havea default; frequently, the default is the way that you'll wantto use the function. So you'll see lines of Perl code likethese:<a href="#FOOTNOTE-16">[16]</a></p><blockquote class="footnote"> <a name="FOOTNOTE-16" /><p>[16]We won't explain it all here, but thisexample pulls some data from an input file or files in one format andwrites some of it out in another format. All of its features arecovered in this book.</p> </blockquote><blockquote><pre class="code">while (<>) { chomp; print join("\t", (split /:/)[0, 2, 1, 5] ), "\n";}</pre></blockquote><p>Written out in full, without using Perl's defaults and<a name="INDEX-22" />shortcuts, thatsnippet would be roughly ten or twelve times longer, so it would takemuch longer to read and write. It would be harder to maintain anddebug, too, with more variables. If you already know some Perl, andyou don't see the variables in that code, that's part ofthe point. They're all being used by default. But to have thisease at the programmer's tasks means paying the price whenyou're learning; you have to learn those defaults andshortcuts.</p><p>Once you become familiar with Perl, you may find yourself spendingless time trying to get shell quoting (or C declarations) right, andmore time surfing the Web, because Perl is a great tool for leverage.Perl's concise constructs allow you to create (with minimalfuss) some very cool one-up solutions or general tools. Also, you candrag those tools along to your next job, because Perl is highly<a name="INDEX-23" /><a name="INDEX-24" />portable and readily available, soyou'll have even more time to surf.</p><p>Perl is a very <a name="INDEX-25" />high-level language. That means thatthe code is quite dense; a Perl program may be around 30% to 70% aslong as the corresponding program in C. This makes Perl faster to
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -