Web Site Hosting
Our Network
Technical Support
Web Site Design
Miscellaneous



 
Perl (Practical Extraction and Report Language) is an interpreted programming language that pattern matches, manipulates information, and is useful for systems administration automation. Over time, it has become the language of choice for most of the CGI's currently in use on the Web.

By default, your VPS1 should already have the Perl5 standard libraries installed. If not, or if you wish to reinstall them, follow the directions below.

Installing Perl5

  1. Connect to your VPS1 via Telnet or SSH, and from the command prompt execute the following commands:

    % cd
    % vinstall perl5

  2. After installing Perl5, point to your new Perl installation by editing your CGI script.

Perl can be called in two ways:

  • Directly from the command line

    % ~/usr/local/bin/perl ./env.cgi

  • Running the program on the first line of the file

You can call Perl by running the program on the first line of the file with the #! notation. For example, if you are creating a script with Perl, open a file and enter #!/usr/local/bin/perl. This action informs the computer that the script is a Perl script.

Duplicating the Virtual Environment

Remember, the same problem of confusing the VPS1 with the physical server can appear when pathing to Perl. When you enter which perl from the command line, the Perl returned is the first Perl seen in your .cshrc$path. If this is Perl4, you may be pathing to the wrong Perl (i.e. /usr/local/bin/perl4).

If you desire to execute the script duplicating the virtual environment, use the virtual command:

% virtual ./env.cgi

The first line in the env.cgi file is #!/usr/local/bin/perl, so the Perl5 binary is used for the script. Perl can also take command line options, which can be useful in debugging scripts. They can also be included on the first line of your script. For example, the following causes Perl to check the syntax of the script:

#!/usr/local/bin/perl -c

The following forces Perl to look in the /usr/local/lib/perl5 directory for include files:

#!/usr/local/bin/perl -I/usr/local/lib/perl5

The following forces Perl to print warnings about various things:

#!/usr/local/bin/perl -w

Note: When a script does not work properly, the -w and -c options can help debug by generating warnings and check for syntax errors. In addition to these options, check your web server error log files for errors.

Checking Your Server's Error Log Files
  1. Connect to your VPS1 via Telnet.
  2. Change directories to the log directory.
  3. Tail the error log.

    % cd ~/www/logs
    % tail error_log

Common Problems and Solutions with Perl Scripts

The following are some common problems and possible solutions that can occur with Perl scripts on a VPS1.

Failure to Upload Your Perl Script in ASCII Mode

Perl scripts, unlike compiled executables, are plain text files. Plain text files should be transferred from your local computer to your VPS1 using ASCII mode (not BINARY mode). Failure to transfer your Perl scripts to your VPS1 in ASCII mode may result in 500 Server Errors.

Problems with Perl5 Scripts

Script requires Perl5, but Perl5 is not on the VPS1.

Or:

The path to Perl that the script uses is #!/usr/local/bin/perl4 rather than #!/usr/local/bin/perl.

Solution

Install Perl5.

Installing Perl5

Connect to your VPS1 via Telnet or SSH, and from the command prompt execute the following commands:

% cd
% vinstall perl5

After installing Perl5, point to your new Perl installation by editing your CGI script.

Editing Your CGI Script
  1. From the command prompt, type:
  2. % cd www/cgi-bin
    % pico my-cgi.cgi

  3. Change the first line of the script from:

    #!/usr/bin/perl

to:

#!/usr/local/bin/perl

This action runs your Perl program with the Perl5 interpreter rather than perl4, located in ~/usr/bin/perl.

The Perl install now installs a hard linked copy of Perl5. This saves space on the VPS1 (about 10.8 megabytes).

Vinstall can also install the linked copy of Perl5:

% vinstall perl5

Improper Path Specification of Perl Interpreter

The first line of a Perl script indicates the path name of the Perl interpreter. In the VPS1 environment, the correct specification of your Perl5 interpreter is /usr/local/bin/perl. If you downloaded a Perl script from a third party source, the Perl interpreter is most often defined based on the author's host environment, which may be different from the VPS1 environment. In addition, if you have uploaded a Perl script to your VPS1, ensure that the script includes the proper path definition to the Perl5 interpreter. The location of the Perl4 interpreter is specified as /usr/local/bin/perl4, whereas the Perl5 interpreter location should be specified as /usr/local/bin/perl.

A Sample Problem with Utilities

Utilities such as sendmail do not seem to work.

Solution

Because the problem is probably a pathing issue (such as /usr/sbin/sendmail being used rather than /bin/sendmail), you must change the paths from physical server paths to VPS1 paths.

Note: To ensure that your script is calling paths to the VPS1 environment, see the previous section entitled "The VPS1 vs. the Physical Server" for more information.

A Sample Problem with a Perl Script Module

A module is not found in the Perl script, which is probably because of a pathing issue (usr or require not pathing to the correct Perl module) or module is not included in the current Perl installation.

Solutions

Any of the following solutions can solve the problem of when a module is not found in the Perl script:

  • Put the module in the same directory in which the Perl script is running and do not path to it (just call it by name with the use or require or other such syntax).
  • Put the module in the directory where your other modules are stored, normally /usr/local/lib/perl5/.
  • Add the path to modules you have created or desire to use into the @INC array. To use this solution, VPS Hosting suggests the O'Reilly books on Perl.
 
 
Copyright 1996-2009 by VPS Hosting. - All Rights Reserved.

FrontPage and Microsoft are Registered Trademarks of Microsoft Corporation. All other Trademarks are the property of their respective owner(s).