Supplemental files and examples for this book can be found at http://examples.oreilly.com/9780596004927/. Please use a standard desktop web browser to access these files, as they may not be accessible from all ereader devices.
All code files or examples referenced in the book will be available online. For physical books that ship with an accompanying disc, whenever possible, weve posted all CD/DVD content. Note that while we provide as much of the media content as we are able via free download, we are sometimes limited by licensing restrictions. Please direct any questions or concerns to .
The Pursuit of Happiness
Perl is a language for getting your job done.
Of course, if your job is programming, you can get your job done with any complete computer language, theoretically speaking. But we know from experience that computer languages differ not so much in what they make possible , but in what they make easy . At one extreme, the so-called fourth generation languages make it easy to do some things, but nearly impossible to do other things. At the other extreme, so-called industrial-strength languages make it equally difficult to do almost everything.
Perl is different. In a nutshell, Perl is designed to make the easy jobs easy, without making the hard jobs impossible.
And what are these easy jobs that ought to be easy? The ones you do every day, of course. You want a language that makes it easy to manipulate numbers and text, files and directories, computers and networks, and especially programs. It should be easy to run external programs and scan their output for interesting tidbits. It should be easy to send those same tidbits off to other programs that can do special things with them. It should be easy to develop, modify, and debug your own programs, too. And, of course, it should be easy to compile and run your programs, and do it portably, on any modern operating system.
Perl does all that, and a whole lot more.
Initially designed as a glue language for Unix, Perl has long since spread to most other operating systems. Because it runs nearly everywhere, Perl is one of the most portable programming environments available today. To program C or C++ portably, you have to put in all those strange #ifdef
markings for different operating systems. To program Java portably, you have to understand the idiosyncrasies of each new Java implementation. To program a shell script portably, you have to remember the syntax for each operating systems version of each command, and somehow find the common factor that (you hope) works everywhere. And to program Visual Basic portably, you just need a more flexible definition of the word portable. :)
Perl happily avoids such problems while retaining many of the benefits of these other languages, with some additional magic of its own. Perls magic comes from many sources: the utility of its feature set, the inventiveness of the Perl community, and the exuberance of the open source movement in general. But much of this magic is simply hybrid vigor; Perl has a mixed heritage, and has always viewed diversity as a strength rather than a weakness. Perl is a give me your tired, your poor language. If you feel like a huddled mass longing to be free, then Perl is for you.
Perl reaches out across cultures. Much of the explosive growth of Perl was fueled by the hankerings of former Unix systems programmers who wanted to take along with them as much of the old country as they could. For them, Perl is the portable distillation of Unix culture, an oasis in the wilderness of cant get there from here. On the other hand, it also works in the other direction: Windows-based web designers are often delighted to discover that they can take their Perl programs and run them unchanged on the companys Unix servers.
Although Perl is especially popular with systems programmers and web developers, thats just because they discovered it first; Perl appeals to a much broader audience. From its small start as a text-processing language, Perl has grown into a sophisticated, general-purpose programming language with a rich software development environment complete with debuggers, profilers, cross-referencers, compilers, libraries, syntax-directed editors, and all the rest of the trappings of a real programming languageif you want them. But those are all about making hard things possible; and lots of languages can do that. Perl is unique in that it never lost its vision for keeping easy things easy.
Because Perl is both powerful and accessible, it is being used daily in every imaginable field, from aerospace engineering to molecular biology, from mathematics to linguistics, from graphics to document processing, from database manipulation to client-server network management. Perl is used by people who are desperate to analyze or convert lots of data quickly, whether youre talking DNA sequences, web pages, or pork belly futures.
There are many reasons for the success of Perl. Perl was a successful open source project long before the open source movement got its name. Perl is free, and it will always be free. You can use Perl however you see fit, subject only to a very liberal licensing policy. If you are in business and want to use Perl, go right ahead. You can embed Perl in the commercial applications you write without fee or restriction. And if you have a problem that the Perl community cant fix, you have the ultimate backstop: the source code itself. The Perl community is not in the business of renting you their trade secrets in the guise of upgrades. The Perl community will never go out of business and leave you with an orphaned product.
It certainly helps that Perl is free software. But thats not enough to explain the Perl phenomenon, since many freeware packages fail to thrive. Perl is not just free; its also fun. People feel like they can be creative in Perl, because they have freedom of expression: they get to choose what to optimize for, whether thats computer speed or programmer speed, verbosity or conciseness, readability or maintainability or reusability or portability or learnability or teachability. You can even optimize for obscurity, if youre entering an Obfuscated Perl Contest.
Perl can give you all these degrees of freedom because its a language with a split personality. Its simultaneously a very simple language and a very rich language. Perl has taken good ideas from nearly everywhere, and installed them into an easy-to-use mental framework. To those who merely like it, Perl is the Practical Extraction and Report Language . To those who love it, Perl is the Pathologically Eclectic Rubbish Lister . And to the minimalists in the crowd, Perl seems like a pointless exercise in redundancy. But thats okay. The world needs a few reductionists (mainly as physicists). Reductionists like to take things apart. The rest of us are just trying to get it together.
There are many ways in which Perl is a simple language. You dont have to know many special incantations to compile a Perl programyou can just execute it like a batch file or shell script. The types and structures used by Perl are easy to use and understand. Perl doesnt impose arbitrary limitations on your datayour strings and arrays can grow as large as they like (so long as you have memory), and theyre designed to scale well as they grow. Instead of forcing you to learn new syntax and semantics, Perl borrows heavily from other languages you may already be familiar with (such as C, and