Perl overview

Perl is a programming language used widely in the UNIX/Linux world to write everything from quick scripts to powerful, broad-featured programs. The following is a description from the perlintro man page:

What is Perl?

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.

Different definitions of Perl are given in perl, perlfaq1 and no doubt other places. From this we can determine that Perl is different things to different people, but that lots of people think it's at least worth writing about.

History

Perl was created in the mid-1980s by Larry Wall. Its original intent was to fill in the gap between so-called "low-level" languages like C and C++, and the higher level scripting languages like awk, sed, and shell scripts. It has evolved considerably since then, becoming the de facto language of choice for many *nix system administrators and power users. It has found broad appeal on the Internet (a mostly *nix based network) as the background code behind many sites on the World Wide Web. A notable example is Slashdot.

Perl on DreamHost

Path to the Perl interpreter

The path to Perl on DreamHost's servers is shown below. This path is standard on *nix based systems and most scripts should not need to be modified.

/usr/bin/perl

mod_perl is currently not supported at DreamHost. You must use FastCGI instead.

DreamHost's Perl version

As of June 2015, DreamHost uses Perl version 5.14.2. As with Python and PHP, you can build another version in your home directory if necessary. However, most Perl programs should work fine with the installed version.

Using Perl Modules

DreamHost has nearly all the common Perl modules installed, as well as many uncommon ones.

To check whether a Perl module is installed on DreamHost's servers, log into your shell account, and then type the following:

[server]$ perl -MThe::Module::Name -e0

where The::Module::Name is, obviously enough, the name of the Perl module you are looking for.

The command outputs nothing when the module is found. If it's not found, an error is thrown.

Installing custom modules

You can install your own modules in your home directory directly. Follow these DreamHost specific instructions for installing CPAN modules.

Perl FastCGI

The perl FCGI module is installed by default on DreamHost servers.

To test if FastCGI is configured and working properly, try this simple 'Hello World' program. Paste this text into a file with the ending .fcgi.

#!/usr/bin/perl

use lib qw( /home/myhome/lib/perl/5.8.4 );
use FCGI;
use Socket qw( :crlf ); # server agnostic line endings in $CRLF

my $counter = 0;
while ( FCGI::accept() >= 0 ) {
   $counter++;

   print
        "Content-Type: text/plain",
        $CRLF,
        $CRLF,
        "Hello World, in Perl FastCGI!",
        $CRLF,
        "I am process $$.",
        $CRLF,
        "I have served $counter request(s).",
        $CRLF;
 }

The $CRLF is a server-neutral line ending equivalent to "\015\012." It will always work. "\n" or even "\r\n" sometimes will not.

If you change the extension of this script to .pl or .cgi so it's handled by regular CGI, you'll notice that the PID is different on every request, and the request counter stays at 1.

Debugging

DreamHost runs suexec and requires that all cgi scripts and the directories in which they reside not be writable by anyone but the owner (i.e., user). This means that you must change the permissions of the script using chmod (see the following example):

[server]$ chmod -R 755 perldir

where perldir is the directory in which your perl CGI resides.

See also