Introduction to Perl

Administrator's picture

Perl stands for ‘Practical Extraction and Reporting Language’, and was created by Larry Wall while he was working on Unix systems for NASA. It was designed with the intention to combine the power of other scripting languages. Because of this, the Perl syntax will be familiar to people who have used other server-side languages. The Unix heritage is visible in the text-based nature of the language, which also makes it ideal to use on the web alongside other text-based languages such as HTML. Perl is an interpreted language, which is ideal for the web as applications are quickly written and often altered.

The Common Gateway Interface (CGI) is a standard set of rules to allow for server/client interaction. Perl programs can be executed this way when a user accesses it via a web browser. In most cases, these programs will have to be stored in a folder on the web space entitled ‘cgi-bin’ and ending with the .cgi suffix. One example of CGI in action is the variables and values displayed in a Google Search URL. When uploading programs to the web server it is important to change its file permissions to allow the program to be executed by all user types. It is also useful to save the file as the same type as the server it will be hosted on (e.g. save as Unix on a Unix server). These steps will help prevent program errors.

As stated, the Perl program syntax will be very similar to those who have coded with scripting languages before. The program should start with the following line of code, which states that this is a Perl program: #! /usr/bin/perl

A content type must also be declared using the ‘print’ function, e.g. print “Content-Type: text/plain\n”;

The \n ensures a new line is created in the eventual output, and the semi-colon has to be placed at the end of all Perl commands. Variables can be declared using the ‘my’ function: my $name = “Paul”; Useful links: Perl.com The Perl Directory CPAN More about Larry Wall

40 people like this