|
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 Virtual Server should already have the Perl5 standard libraries
installed. If not, or if you wish to reinstall them,
follow the directions below.
Installing Perl5
- Connect to your Virtual Server 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.
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 Virtual Server 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
- Connect to your Virtual Server via Telnet.
- Change directories
to the log directory.
- 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 Virtual Server.
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 Virtual Server using ASCII mode (not BINARY
mode). Failure to transfer your Perl scripts to your
Virtual Server in ASCII mode may result in 500 Server
Errors.
Problems with Perl5
Scripts
Script requires Perl5,
but Perl5 is not on the Virtual Server.
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 Virtual Server 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
- From the command
prompt, type:
% cd www/cgi-bin
% pico my-cgi.cgi
- 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 Virtual Server (about 10.8 megabytes).
Vinstall can also
install the linked copy of Perl5:
% vinstall perl5
Improper Path Specification
of Perl InterpreterThe first line of a Perl
script indicates the path name of the Perl interpreter.
In the Virtual Server 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 Virtual Server environment. In addition, if
you have uploaded a Perl script to your Virtual Server,
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.
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
Virtual Server paths.
Note: To ensure
that your script is calling paths to the Virtual Server
environment, see the previous section entitled "The
Virtual Server vs. the Physical Server" for more
information.
A Sample Problem with
a Perl Script ModuleA 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, Enetrics Communications suggests
the O'Reilly books on Perl.
|