Perl
Perl Basics
Perl - Practical Extraction and Report Language - is a general-purpose language that excels at file and string manipulation due to its built-in support for Regular Expressions (see 'More Unix'). Understanding regular expressions is key to harnessing the full potential of Perl.
Regular expressions are used throughout Unix in programs such as grep, awk and sed. They provide a general language for describing sets of strings (i.e. words, sentences etc) and are used for pattern matching. For example, if you have a file containing a list of customers, a regular expression could be used to count the number of 'Smith's there were, or find a customer whose name began with a certain letter.
Perl has all the usual functions, plus it has database support through libraries, and many other features useful to webmasters. It's a very flexible language, with many powerful and subtle features to make life easier for the programmer. It's easy to write very concise and efficient programs in Perl once you get to know it.
Perl programs can be run at the Unix command line, scheduled, triggered by external programs (like qmail), or they can be run from your web pages using SSI...
Server Side Includes (SSI) allows you to run and show the output from a Perl script or other Unix executable file, in a web page.
SSI is used to provide most of the hit counters you see (and a lot of other things too). If you read the source code for a web page with such a counter - you'll just see the text '1000 visitors'. However - the web page on the server will have something like the following code in it's place:
<!--#include virtual="/cgi-bin/count.pl?countpage"-->
This includes the output from the 'count.pl' script.
Note, you can do exactly the same thing with PHP using its 'include' command - you can run Perl programs & PHP commands from the same PHP web page!
Web pages with SSI in them usually need to be given a .shtml extension (i.e. index.shtml) otherwise they are not processed.
Perl Resources
The first Perl documentation set to get is the Perl man pages. I'd strongly suggest you download the entire set to your 'Manuals' directory using a website download tool. These contain the definitive specification for Perl. They aren't the easiest to read however, so some of the following may help:
| Books (from Amazon.com) |
>Programming Perl by Larry Wall, Tom Christiansen, Jon Orwant |
Larry Wall wrote Perl itself - and then he wrote Programming Perl. Better yet, he writes amusingly and well - all of which comes across in this latest edition of the definitive guide to the language. |
>Perl Pocket Reference by Johan Vromans |
The Perl Pocket Reference is an invaluable reference for those who find themselves frequently searching for a quick answer to a question or reminder of a syntax rule. This handy, well-organized quick reference condenses stacks of Perl documentation down to the most essential at-your-fingertips facts. |
>Perl Cookbook by Tom Christiansen, Nathan Torkington |
The Perl Cookbook is a superb collection of coding snippets which cover all manner of subject areas in a fashion that proves suitable for beginners and established programmers alike. |
>Learning Perl by Randal L. Schwartz, Tom Phoenix |
Learning Perl draws on the expertise of two of the major supporters of this highly flexible language, Randal Schwatrz and Tom Christiansen, to produce an introductory manual which manages to be concise yet informative throughout. |
>Programming the Perl DBI: Database Programming with Perl by Alligator Descartes, Tim Bunce |
The interestingly named Alligator is a database programmer and Perl module developer. Tim Bunce wrote DBI--the Perl DataBase Interface. DBI is a series of Perl modules providing a standard API to a variety of database engines. Perl DBI is a natural choice for dynamically generating Web pages from databases. |
| Online Resources |
Picking Up Perl by Bradley M. Kuhn |
This is a freely distributable perl tutorial. |
| Perl.com |
This is O'Reilly's (the publisher_ website and contains lots of useful info, docs, examples etc. |
Perl 5 Reference Guide by Rex Swain |
A free online, single large page reference for Perl. |
| FreePerlCode.com |
A website devoted to perl - loads of example scripts! |
| HotScripts.com |
Have thousands of free Perl (and other) scripts... |
|
|