The meaning of Perl (Practical Extraction and Report Language) is quite a good description of what this script language actually does:

  • Extraction to look into files and to “extract” the data that is important for you;
  • Report for generating reports on output, based on the required information;
  • It is an Practical language because it is easier to write these kinds of scripts in Perl than for example in C.

Perl was devised in 1987 by Larry Wall, who was already known at the time in the world of UNIX software (he wrote the programs patch and rn (a usernet news reader).

Perl is a script language that consists of pieces of many UNIX programs and programming/script languages, including sed, grep, awk, shell scripting and C. Perl is available on many operating systems, including UNIX, Linux, Windows and Macintosh.

Perl is commonly used in web applications, CGI scripts in particular are written in Perl. Perl can be used separately as a script, but also as ‘glue’ between different systems. Perl files end with .pl or .cgi (CGI means Common Gateway Interface) and are so-called “server side” scripts. This means that the source code of your Perl scripts are “interpreted” (parsed) by a parser, which is why you only see the HTML code in your browser.

At VEVIDA you can use Perl scripts as standard. A cgi-bin directory is not present. You can create this yourself using your favourite FTP program. Remember that this directory must be placed in the WWW directory. The installed version is 5.8.9.825.

If the /cgi-bin folder needs write permissions to put scripts in place, you can assign these rights (write permissions for the IUSR) via MyVevida. Place the following in the text box once you have placed the cgi-bin in the WWW directory: wwwcgi-bin, assign rights. Innumerable scripts have been written for Apache on a Unix, Linux system. The CHMOD command is used for this. VEVIDA uses Windows Server 2003 web servers for which the CHMOD command does not exist.

However, normally the IUSR write permissions are not necessary.

The PATH to the Perl executable is c:/perl/bin. A standard, the Perl ISAPI dll is used, so this item of information is not necessary for scripts.

If you have problems with the use of Perl/CGI scripts, you can always request help via the Support section on MyVevida. Do give extra information here, such as where we can find your scripts, what error messages you get, etc. Unfortunately, we cannot guarantee that we can resolve your problems. For this reason, first try to find your answer on the internet.
Links to sites about Perl/CGI can be found on our Links to various (technical) information page and Perldoc.com.

Tip:
Ensure that you upload your Perl files by FTP in ASCII mode (plain/text). If you upload them in BINARY mode, the script will not work.

Tips and advice

Newlines

In Perl, newlines are defined differently than for example in ASP. Here is a short explanation:

\n is equivalent to <LF> (LineFeed).
\r\n is equivalent to <CR><LF> (CarriageReturn LineFeed).

Optimising print() calls

Printing data on screen is a relatively heavy, resource consuming operation. For many print() statements (calls), it can take a long time before the script is fully loaded. Each Perl script that has many print() calls can be improved considerably in speed by collecting as much data as possible before printing it. Perl makes this easy with the ‘.=’ operator (concatenation).
For example, the following code

$data = "Hello";
print $data;
$data = " world";
print $data;
$data = "\r\n";
print $data;

is rewritten to:

$data = "Hello";
$data .= " world";
$data .= "\r\n";
print $data;

Or:

print "Hello world,
This is a multi
line print statement\r\n";

which makes the script load faster. This also applies to the other, frequently used calls.

Hello World

The following pieces of code print a simple Hello World HTML page, but in two different ways. Function oriented:

#!C:/Perl/bin
use CGI qw/:standard/;     # load standard CGI routines
print header,              # create the HTTP header
start_html('hello world'), # start the HTML
h1('hello world'),         # level 1 header
end_html;                  # end the HTML

Or object oriented (OO):

#!C:/Perl/bin
use CGI;                   # load CGI routines
$q = new CGI;              # create new CGI object
print $q->header,       # create the HTTP header
$q->start_html('hello world'),  # start the HTML
$q->h1('hello world'),  # level 1 header
$q->end_html;           # end the HTML

The difference is that when the object oriented method is not used, a set of functions is imported to our name space (usually the standard functions). No CGI object needs to be created.

Date

The date function is not supported, instead of this you can use the following code to call up the date:

my ($day, $mon, $year) = (localtime)[3, 4, 5];
$mon++; # 0-based index
$year = $year + 1900;
$date = sprintf ("%02i/%02i/%02i",$day, $mon, $year);

If you also want the time with this:

my ($day, $mon, $year, $hour, $min) = (localtime)[3, 4, 5, 2, 1];
$mon++; # 0-based index
$year = $year + 1900;
$date = sprintf ("%02i/%02i/%02i %02i:%02i", $day, $mon, $year, $hour, $min);

Sendmail

Sendmail is not recognized on our Windows web servers. This means that it cannot be used. A reference in your (email) script to /usr/lib/sendmail will not work.

A good alternative option is to use the Mail::SendMail module. Documentation about this module can be found on http://theoryx5.uwinnipeg.ca/CPAN/data/Mail-Sendmail/Sendmail.html and http://alma.ch/perl/Mail-Sendmail-FAQ.html.

localhost is also available as an email server

Extracting data from forms

If you have a contact form, for example, which has data that are sent to a CGI email script by means of the POST method, you can incorporate these data into the CGI script with the function param(‘veld_naam’);.

You must then use either “use CGI;” or “use CGI qw/:standard/;” in your script.

Example:
contact.html:

<form method="post" action="/cgi-bin/mail.pl">
Uw naam: <input size="20">
Uw email: <input size="20">
Uw bericht: <textarea rows="10" cols="60">

mail.pl:

use CGI qw/:standard/;
$mail{Message} = "Naam: ". param('Name') . "\n";
$mail{Message} .= "Email: ". param('Email') . "\n";
$mail{Message} .= "Bericht: ". param('Message') . "\n";

A ‘.’ (dot) is a concatenation or operator that links different strings to each other.
You could for example also use

$mail{Message} = "Naam: ". param('Name') . "Email: ". param('Email') . "\n\n";

in the script.

Several examples of (environment) variables

Because a backslash (\) is also used in Perl/CGI commands, for example for the newlines, this must be escaped if this is not a command. This is done by putting in an extra backslash (\\). C:\temp then becomes C:\\temp or C:/temp.

$PROGNAME="http://www.yourdomain.com/cgi-bin/script.cgi";
# $PROGNAME is the URL of this script.

$BASEDIR="D:\\www\\yourdomain.com\\www\\cgi-bin\\";
# or
$BASEDIR="D:/www/yourdomain.com/www/cgi-bin";
# In $BASEDIR, this is where you define the directory in which the data are saved.

$SITEURL="http://www.yourdomain.com";
# This is where the URL of your site is defined.

$SITENAME="The name of your site";
# The name of your site is defined here, i.e. the title.

Attention: These are only examples; the actual definitions can vary per script!

The following script prints all the available Perl environment variables:

#!C:/Perl/bin
# 
# Print Perl environment variabelen
# (c)2006-2007 VEVIDA Services bv - Jan Reilink <info@vevida.com>
######

use CGI;
use CGI::Carp "fatalsToBrowser";
use strict;

my $query = new CGI;
my $running_under_perlis = $ENV{'PERLXS'};

if ($running_under_perlis ne 'PerlIS') {
  print $query->header;
}

print $query->start_html("Environment variabelen"),
$query->p($query->b("Environment variabelen")),
$query->start_table;

foreach my $key (keys(%ENV)){
  print "<tr><td>$ENV{$key}:</td><td>$ENV{$key}</td></tr>\n"; 
}
print $query->end_table,
$query->end_html;

ActivePerl Documentation and Support

The ActivePerl Documentation and Support can be found on
http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/faq/ActivePerl-faq3.html
For Windows: http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/faq/Windows/ActivePerl-Winfaq8.html
Modules: http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/lib/ActivePerl.html

The following script prints all the installed Perl modules:

#!C:/Perl/bin
# 
# Print geinstalleerde Perl modules
# (c)2006-2007 VEVIDA Services bv - Jan Reilink <info@vevida.com>
######

use CGI;
use CGI::Carp "fatalsToBrowser";
use ExtUtils::Installed;
use strict;

my $query = new CGI;
my $running_under_perlis = $ENV{'PERLXS'};

if ($running_under_perlis ne 'PerlIS') {
  print $query->header;
}

print $query->start_html("Perl modules"),
  $query->p($query->b("Geinstalleerde Perl modules -- versies")),
  $query->start_table;

my $instmod = ExtUtils::Installed->new();
foreach my $module ($instmod->modules()) {
  my $version = $instmod->version($module) || "???";
  print "<tr><td><a href='http://search.cpan.org/search?module=$module' target='_blank'>
  $module</a></td>
  <td>--t</td>
  <td>$version</td>
  </tr>\n";
}
print $query->end_table,
$query->end_html;

Attention: Perl ISAPI vs CGI

Perl can be run in two modes on the VEVIDA web servers: as an ISAPI filter (PerlIs) and in CGI mode.

By setting Perl as ISAPI, scripts function faster because it is not necessary to start a separate process (and to reserve memory) for every call. It is difficult to have the web server crash when CGI mode is used (because a separate process is started for every call), but because the PerlIS DLL runs in the memory of the application, it can happen that the Perl parser crashes due to programming errors.

Extra care must be taken when making PerlIS applications.

Most web servers are set to PerlIs, a few on CGI mode. When a web server (or individual web site) is set to PerlIs, then a PERLXS environment variable is available. With Perl in CGI mode this is missing. This environment variable can therefore be used as a check:

my $running_under_perlis = $ENV{'PERLXS'};
if ($running_under_perlis ne 'PerlIS') {
  # de environment variabele PerlIs is niet beschikbaar, 
  # print de Content-type header
  print "Content-type: text/html\n\n";
  print "Perl in CGI-mode.\n";
}
else {
  print "Perl als ISAPI.\n";
}

There are a number of important differences between PerlIs and CGI. As mentioned earlier, PerlIs runs in the memory and a new process is started each time for Perl CGI. Other differences include the working directory. PerlIs runs from the current directory where there is the script: ./. This makes it possible to call up files via use ‘./library.pm’;. For Perl as CGI this does not apply and the full PATH must be given: use ‘D:/www/example.com/www/library.pm’;.

Another important difference is printing from HTTP headers. A standard, Perl CGI does not send a Content-type header, this must be specifically printed in the script. PerlIs does send this as standard. When this is also printed in the script, this gives error messages.

PerlIs (via the CGI class):

use CGI;
use CGI::Carp "fatalsToBrowser";
my $query = new CGI;

print $query->start_html("HTML heading"),
$query->p("some text in a P-alinea block"),
$query->blockquote(
  a({href=>"http://www.vevida.com"},"a link to VEVIDA.COM in a blockquote block")),
$query->end_html;

Perl CGI (via the CGI class):

use CGI;
use CGI::Carp "fatalsToBrowser";
my $query = new CGI;

print $query->header,                # print Content-Type header text/html
$query->start_html("HTML heading"),
$query->p("some text in a P-alinea block"),
$query->blockquote(
  a({href=>"http://www.vevida.com"},"a link to VEVIDA.COM in a blockquote block")),
$query->end_html;

If Perl scripts need to be able to run in both modes, it is possible to use the environment variable check in the following way, for example:

my $running_under_perlis = $ENV{'PERLXS'};
if ($running_under_perlis ne 'PerlIS') {
  print "Content-type: text/html\n\n";
  print "Hallo wereld!\n";
}
else {
  print "Hallo wereld!\n";
}

Or, via the CGI class:

use CGI;
use CGI::Carp "fatalsToBrowser";
my $query = new CGI;
my $running_under_perlis = $ENV{'PERLXS'};

if ($running_under_perlis ne 'PerlIS') {
  print $query->header;
}
print $query->start_html("HTML heading"),
$query->p("some text in an P-alinea block"),
$query->blockquote(
  a({href=>"http://www.vevida.com"},"a link to VEVIDA.COM in a blockquote block")),
$query->end_html;
exit();

Attention: the CGI class is separate from Perl as an ISAPI module or in CGI mode.

« Back

Customer service

Cannot find what you are looking for? Please contact our customer service:

We are glad to be of service.