Home Scripts and Programs Glossary and Articles Other Resources Contact Us About Us
Adult Hosting
Budget Hosting
Coldfusion Hosting
Colocation
Dedicated Servers
Game Servers
Linux Hosting
Managed Hosting
Reseller Hosting
Ruby on Rails Hosting
Virtual Private Servers
Windows Hosting
Advertiser Login
Create An Account
More Info
Perl
Perl, also Practical Extraction and Report Language (a backronym, see below) is an interpreted procedural programming language designed by Larry Wall. Perl borrows features from C, shell scripting (sh), awk, sed, Lisp, and (to a lesser extent) many other programming languages.

Overview

The perlintro(1) man page states:

Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.

The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). Its major features are that it's easy to use, supports both procedural and object-oriented (OO) programming, has powerful built-in support for text processing, and has one of the world's most impressive collections of third-party modules.

Language features

The overall structure of Perl derives broadly from the programming language C. Perl is a procedural programming language, with variables, expressions, assignment statements, brace-delimited code blocks, control structures, and subroutines.

Perl also takes features from shell programming. All variables are marked with leading sigils. Sigils unambiguously identify variable names, allowing Perl to have a rich syntax. Importantly, sigils allow variables to be interpolated directly into strings. Like the Unix shells, Perl has many built-in functions for common tasks, like sorting, and for accessing system facilities.

Perl takes lists from Lisp, associative arrays from awk, and regular expressions from sed. These simplify and facilitate all manner of parsing, text handling, and data management tasks.

In Perl 5, features were added that support complex data structures, first-class functions (i.e. closures as values), and an object-oriented programming model. These include references, packages, and class-based method dispatch. Perl 5 also saw the introduction of lexically scoped variables, which make it easier to write robust code, and modules, which make it practical to write and distribute libraries of Perl code.

All versions of Perl do automatic data typing and memory management. The interpreter knows the type and storage requirements of every data object in the program; it allocates and frees storage for them as necessary. Legal type conversions are done automatically at run time; illegal type conversions are fatal errors.

Applications

Perl has many and varied applications.

It has been used since the early days of the Web to write CGI scripts, and is an integral component of the popular LAMP (Linux / Apache / MySQL / (Perl / PHP / Python)) platform for web development. Perl has been called "the glue that holds the web together". Large projects written in Perl include Slash, early implementations of PHP [1], and UseModWiki, the wiki software used in Wikipedia until 2002.

Perl is often used as a "glue language", tying together systems and interfaces that were not specifically designed to interoperate. Systems administrators use Perl as an all-purpose tool; short Perl programs can be entered and run on a single command line.

Perl is widely used in finance and bioinformatics, where it is valued for rapid application development, ability to handle large data sets, and the availability of many standard and 3rd-party modules.

Implementation

Perl is implemented as a core interpreter, written in C, together with a large collection of modules, written in Perl and C. The source distribution is, as of 2005, 12 MB when packaged in a tar file and compressed. The interpreter is 150,000 lines of C code and compiles to a 1 MB executable on typical machine architectures. Alternately, the interpreter can be compiled to a link library and embedded in other programs. There are nearly 500 modules in the distribution, comprising 200,000 lines of Perl and an additional 350,000 lines of C code. Much of the C code in the modules consists of character encoding tables.

The interpreter has an object-oriented architecture. All the elements of the Perl language—scalars, arrays, hashes, coderefs, file handles—are represented in the interpreter by C structs. Operations on these structs are defined by a large collection of macros, typedefs and functions; these constitute the Perl C API. The Perl API can be bewildering to the uninitiated, but its entry points follow a consistent naming scheme, which provides guidance to those who use it.

The execution of a Perl program divides broadly into two phases: compile-time and run-time. At compile time, the interpreter parses the program text into a syntax tree. At run time, it executes the program by walking the tree. The text is parsed only once, and the syntax tree is subject to optimization before it is executed, so the execution phase is relatively efficient. Compile-time optimizations on the syntax tree include constant folding, context propagation, and peephole optimization.

Perl is a dynamic language and has a complex grammar that cannot be parsed by a straight Lex/Yacc lexer/parser combination. Instead, it implements its own lexer, which coordinates with a modified GNU bison parser to resolve ambiguities in the language. It is said that "only perl can parse Perl", meaning that only the Perl interpreter (perl) can parse the Perl language (Perl). The truth of this was attested to by the persistent imperfections over a 15 year period of other programs that undertook to parse Perl, such as source code analyzers and auto-indenters.

With the release of the Perl Parsing Interface at OSCON 2005 appearing to disprove the principle, the problem has been clarified to show that while dynamic language programs can be parsed into a document structure (something that the perl interpreter itself cannot do) it is impossible to do so for the purpose of execution. Usage has since begun to slowly change to the more accurate "Only perl can run Perl", although Argumentum ad nauseam may mean it never fully supplants the original.

Maintenance of the Perl interpreter has become increasingly difficult over the years. The code base has been in continuous development since 1994. The code has been optimized for performance at the expense of simplicity, clarity, and strong internal interfaces. New features have been added, yet virtually complete backwards compatibility with earlier versions is maintained. The size and complexity of the interpreter is a barrier to developers who wish to work on it.

Perl is distributed with some 90,000 functional tests. These run as part of the normal build process, and extensively exercise the interpreter and its core modules. Perl developers rely on the functional tests to ensure that changes to the interpreter do not introduce bugs; conversely, Perl users who see the interpreter pass its functional tests on their system can have a high degree of confidence that it is working properly.

There is no written specification or standard for the Perl language, and no plans to create one for the current version of Perl. There has only ever been one implementation of the interpreter. That interpreter, together with its functional tests, stands as a de facto specification of the language.

Availability

Perl is free software, and is licensed under both the Artistic License and the GNU General Public License. It is available for most operating systems. It is particularly prevalent on Unix and Unix-like systems (such as Linux, FreeBSD, and Mac OS X), and is growing in popularity on Microsoft Windows systems.

Perl has been ported to over a hundred different platforms. Perl can, with only six reported exceptions, be compiled from source on all Unix-like, POSIX-compliant or otherwise Unix-compatible platforms, including AmigaOS, BeOS, Cygwin, and Mac OS X. It can be compiled from source on Windows; however, many Windows installations lack a C compiler, so Windows users typically install a binary distribution, such as ActivePerl or IndigoPerl. A special port, MacPerl, is available for Mac OS Classic.

Database interfaces

Perl is widely favored for database applications. Its text handling facilities are good for generating SQL queries; arrays, hashes and automatic memory management make it easy to collect and process the returned data.

In early versions of Perl, database interfaces were created by relinking the interpreter with a client-side database library. This was somewhat clumsy; a particular problem was that the resulting perl executable was restricted to using just the one database interface that it was linked to. Also, relinking the interpreter was sufficiently difficult that it was only done for a few of the most important and widely used databases.

In Perl 5, database interfaces are implemented by Perl DBI modules. The DBI (Database Interface) module presents a single, database-independent interface to Perl applications, while the DBD:: (Database Driver) modules handle the details of accessing some 50 different databases. There are DBD:: drivers for most ANSI SQL databases.

Language design

The design of Perl can be understood as a response to three broad trends in the computer industry: falling hardware costs, rising labor costs, and improvements in compiler technology. Many earlier computer languages, such as Fortran and C, were designed to make efficient use of expensive computer hardware. In contrast, Perl is designed to make efficient use of expensive computer programmers.

Perl has many features that ease the programmer's task at the expense of greater CPU and memory requirements. These include automatic memory management; dynamic typing; strings, lists, and hashes; regular expressions; introspection and an eval() function.

Larry Wall was trained as a linguist, and the design of Perl is very much informed by linguistic principles. Examples include Huffman coding (common constructions should be short), good end-weighting (the important information should come first), and a large collection of language primitives. Perl favors language constructs that are natural for humans to read and write, even where they complicate the Perl interpreter.

Perl syntax reflects the idea that "things that are different should look different". For example, scalars, arrays, and hashes have different leading sigils. Array indices and hash keys use different kinds of braces. Strings and regular expressions have different standard delimiters. This approach can be contrasted with languages like Lisp, where the same S-expression construct and basic syntax is used for many different purposes.

Perl has features that support a variety of programming paradigms, such as procedural, functional, and object-oriented. At the same time, Perl does not enforce any particular paradigm, or even require the programmer to choose among them.

There is a broad practical bent to both the Perl language and the community and culture that surround it. The preface to Programming Perl begins, "Perl is a language for getting your job done." One consequence of this is that Perl is not a tidy language. It includes features if people use them, tolerates exceptions to its rules, and employs heuristics to resolve syntactical ambiguities. Discussing the variant behaviour of built-in functions in list and scalar context, the perlfunc(1) man page says,

In general, they do what you want, unless you want consistency.

Perl has several mottos that convey aspects of its design and use. One is "There's more than one way to do it." (TMTOWTDI, usually pronounced 'Tim Toady'). Others are "Perl: the Swiss Army Chainsaw of Programming Languages" and "No unnecessary limits". A stated design goal of Perl is to make easy tasks easy and difficult tasks possible. Perl has also been called "The Duct Tape of the Internet".

Pro

Programmers who like Perl typically cite its power, expressiveness, and ease of use. Perl provides infrastructure for many common programming tasks, such as string and list processing. Other tasks, such as memory management, are handled automatically and transparently. Programmers coming from other languages to Perl often find that whole classes of problems that they have struggled with in the past just don't arise in Perl. As Larry Wall put it,

What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?

Besides its practical benefits, many programmers simply seem to enjoy working in Perl. Early issues of The Perl Journal had a page titled "What is Perl?" that concluded

Perl is fun. In these days of self-serving jargon, conflicting and unpredictable standards, and proprietary systems that discourage peeking under the hood, people have forgotten that programming is supposed to be fun. I don't mean the satisfaction of seeing our well-tuned programs do our bidding, but the literary act of creative writing that yields those programs. With Perl, the journey is as enjoyable as the destination ...

Whatever the reasons, there is clearly a broad community of people who are passionate about Perl, as evidenced by the thousands of modules that have been contributed to CPAN, and the hundreds of design proposals that were submitted as RFCs for Perl 6.

Con

A common complaint is that Perl is ugly. In particular, its prodigious use of punctuation puts off some people; Perl source code is sometimes likened to "line noise". In The Python Paradox, Paul Graham both acknowledges and responds to this:

At the mention of ugly source code, people will of course think of Perl. But the superficial ugliness of Perl is not the sort I mean. Real ugliness is not harsh-looking syntax, but having to build programs out of the wrong concepts. Perl may look like a cartoon character swearing, but there are cases where it surpasses Python conceptually.

Another criticism is that Perl is excessively complex and compact, and that it leads to "write-only" code, that is, to code that is virtually impossible to understand after it has been written. It is, of course, possible to write obscure code in any language, but Perl has perhaps more than the usual share of terse, complex and arcane language constructs to exacerbate the problem. Perl supports many such features for backwards compatibility, and for use where maintainability is expressly not a concern, such as programs that are entered and run directly on the command line.

The freewheeling language style that delights some Perl programmers concerns and dismays others. For example, the Perl 5 object model does not enforce data security: access to private data is restricted only by convention, not the language itself. An object created in one place may easily be modified in another; there may not be any single place where its state is definitively established. There are techniques for addressing these issues, but they are non-native and little used.

Perl is not efficient at processor-bound tasks, and Perl data structures generally use more memory than comparable data structures in languages like C and C++.

History

Larry Wall began work on Perl in 1987, and released version 1.0 to the comp.sources.misc newsgroup on December 18, 1987. The language expanded rapidly over the next few years. Perl 2, released in 1988, featured a better regular expression engine. Perl 3, released in 1989, added support for binary data.

Until 1991, the only documentation for Perl was a single (increasingly lengthy) man page. In 1991, Programming Perl (the Camel Book) was published, and became the de facto reference for the language. At the same time, the Perl version number was bumped to 4, not to mark a major change in the language, but to identify the version that was documented by the book.

Perl 4 went through a series of maintenance releases, culminating in Perl 4.036 in 1993. At that point, Larry Wall abandoned Perl 4 to begin work on Perl 5. Perl 4 remains at version 4.036 to this day.

Development of Perl 5 continued into 1994. The perl5-porters mailing list was established in May 1994 to coordinate work on porting Perl 5 to different platforms. It remains the primary forum for development, maintenance, and porting of Perl 5.

Perl 5 was released on October 17, 1994. It was a nearly complete rewrite of the interpreter, and added many new features to the language, including objects, references, packages, and modules. Importantly, modules provided a mechanism for extending the language without modifying the interpreter. This allowed the core interpreter to stabilize, even as it enabled ordinary Perl programmers to add new language features.

On October 26, 1995, the Comprehensive Perl Archive Network (CPAN) was established. CPAN is a collection of web sites that archive and distribute Perl sources, binary distributions, documentation, scripts, and modules. Originally, each CPAN site had to be accessed through its own URL; today, the single URL http://www.cpan.org automatically redirects to a CPAN site.

As of 2006, Perl 5 is still being actively maintained. It now includes Unicode support. The latest stable release is Perl 5.8.8.

Future

Main article: Perl 6

At the 2000 Perl Conference, Jon Orwant made a case for a major new language initiative. This led to a decision to begin work on a redesign of the language, to be called Perl 6. Proposals for new language features were solicited from the Perl community at large, and over 300 RFCs were submitted.

Larry Wall spent the next few years digesting the RFCs and synthesizing them into a coherent framework for Perl 6. He has presented his design for Perl 6 in a series of documents called apocalypses, which are numbered to correspond to chapters in Programming Perl ("The Camel Book"). The current, unfinalized specification of Perl 6 is encapsulated in design documents called Synopses, which are numbered to correspond to Apocalypses.

Perl 6 is not intended to be backwards-compatible, though there will be a compatibility mode.

In 2001, it was decided that Perl 6 would run on a cross-language virtual machine called Parrot. This will mean that other languages targeting the Parrot will gain native access to CPAN and will allow some level of cross-language development.

In 2005 Audrey Tang created the pugs project, an implementation of Perl 6 in Haskell. This was and continues to act as a test platform for the Perl 6 language (separate from the development of the actual implementation) allowing the language designers to explore. The pugs project resulted in an active Perl/Haskell cross-language community centred around the Freenode #perl6 irc channel.

A number of features in the Perl 6 language now show similarities with Haskell, and Perl 6 has been embraced by the Haskell community as a potential scripting language.

As of 2006 Perl 6, Parrot, and pugs are under active development.

CPAN

Main article: CPAN

CPAN, the Comprehensive Perl Archive Network, is a collection of mirrored web sites that serve as a primary archive and distribution channel for Perl sources, distributions, documentation, scripts, and—especially—modules. It is commonly browsed with the search engine http://search.cpan.org/.

There are currently over 8,800 modules available on CPAN, contributed by over 2,500 authors. Modules are available for a wide variety of tasks, including advanced mathematics, database connectivity, and networking. Essentially everything on CPAN is freely available; much of the software is licensed under either the Artistic License, the GPL, or both. Anyone can upload software to CPAN via PAUSE, the Perl Authors Upload Server.

Modules on CPAN can be downloaded and installed by hand. However, it is common for modules to depend on other modules, and following module dependencies by hand can be tedious. Both the CPAN.pm module (included in the Perl distribution) and the improved CPANPLUS module offer command line installers that understand module dependencies; they can be configured to automatically download and install a module and, recursively, all modules that it requires.


 
Site Map | Policies | Contact