NavigationSearch![]() Unless otherwise stated, content on this site is licensed under a Creative Commons Attribution -NonCommercial -ShareAlike 2.0 Canada License.
|
Introduction to PerlOverviewPerl is a general purpose programming language with roots in text processing. It was originally called "Pearl" but the name conflicted with another programming language of the same name. Backronyms: Practical Extraction & Reporting Language. "Perl" (uppercase) refers to the language HistoryPerl was first released December 1987. It was created by Larry Wall, then a systems administrator with JPL, to produce reports from multiple servers on a wide area network. Wall remains the "Benevolent Dictator" overseeing development of the language, which as it stands now represents the contribution of many, many people. Wall trained as a linguist before becoming a sysadmin, and that definitely had an affect on the development of the Perl language, particularly its tolerance of ambiguity and contextual interpretation. Perl 5 was released in 1994. Perl 5 is still being actively maintained, is the most commonly used version of the language, and is what we will be looking at in this course. Perl 6 is in development, and has been for a long time. It is questionable as to whether version 6 will ever be as widely implemented as its predecessor. In the early days of the web (mid-90s), Perl gained a lot of traction because web programming involves processing a lot of text (generally in the form of HTML). As specialized web-centric languages like PHP rose to prominence, Perl has become less important for web development, but it still has a place in that niche. Perl was and remains an early example of a really successful open source project. Open source is a form of software licensing designed to foster community participation in software development. See Eric Raymond's Cathedral and the Bazaar (http://www.catb.org/~esr/writings/) for an interesting discussion of the open source licensing model. Design ConceptsOne of Wall's central concepts with Perl was to create a language where the programmer could rough out ideas and then refine them later, much like one does when writing an essay. This is opposed to a more traditional model of programming, where everything needs to be planned out in advance, before a single line of code is written. This makes Perl somewhat suspect to corporate IT shops, which tend to prefer languages like Java that enforce some design constraints and discourage experimentation. Perl is an interpreted language, which means that you can write a script, save it and run it without any intermediate steps. This is a boon to rapid development, because you can write your scripts iteratively. Write a bit, test, debug. Repeat as necessary. This convenience is bought with a sacrifice in execution speed, because Perl code needs to be processed by another program called an interpreter at runtime. This sacrifice is generally well worth it, and in most cases not even noticable. Compiled languages run faster, because compiled programs are translated permanently to machine language before they are run; they don't have to be processed by an interpreter every time. C is an example of a compiled language. However, the compilation phase can add a significant amount of time to the process of writing and debugging code. For the kinds of projects you're likely to be working on as librarians, compiled languages would likely be overkill. Perl was initially designed to run under UNIX, but it soon became available for just about every operating system in common use. It's important to be aware of its origins, as Perl retains some UNIX conventions even in the Windows version - forward slashes as directory separators, for example. Why Perl?The question may arise as to why we are studying Perl rather than, say, C++ or Java. Languages are optimized for different things. Perl's roots in text processing & data manipulation make it highly relevant to library work, because a lot of what librarians work with is text. The availability of a number of library-related perl modules is another consideration, of which more in a moment. Also, Perl's C-like syntax has wide applicability for learning other languages. Anyone who knows Perl can pick up PHP, Python, Java more easily. Strengths and ShortcomingsAs with any programming language, Perl has both strengths & shortcomings. Flexibility is key. "More than one way to do it" is kind of a perl mantra. Perl supports a wide range of coding styles & programming practices (eg. procedural, functional, Object Oriented). Perl has been called the "Swiss army chainsaw" of programming, because it glues together a lot of functions that were previously available in only in disparate programming languages and utilities. It was a philosophical decision on the part of Larry Wall to permit as much flexibility as possible, which can be seen as both good and bad. Because it's flexible, Perl is more open to writing confusing code. It's sometimes called a write-only language by its detractors, which is to say, you can write it, but you won't be able to read it later. It also exhibits some odd default behaviours, although it wouldn't make much sense to go into them at this point. As mentioned above, another core strength of Perl is the availability of a wide range of modules that allow you to write fairly sophisticated programs without a great deal of sophisticated knowledge. We will be looking at a couple of such modules later in the course, specifically MARC::Record and XML::Writer, which enable you to manipulate MARC records and create valid XML, respectively. There are many, many other modules that we won't be covering here. There's even a Z39.50 module that lets you use perl to query library catalogues and other Z-servers. Caveat ScholasticusIn two days, we are only going to be able to skim the surface of the language. There is a lot to perl, and to programming languages in general. Becoming even moderately competent will require a lot of work outside the class. |