Installing Perl

Strawberry Perl

Introduction

Many sites require the use of a programming language to deliver content to the visitor and receive information from them even if it is a simple form. The Common Gateway Interface method is one way to do this interaction, but there are newer methods, such as application servers, FastCGI, ISAPI, NSAPI and others.

I don't need such complications as most of my pages are static, but I eventually decided I needed some sort of CGI scripting. I decided to go with Perl instead of PHP or Python, because the log analyzer AWStats, I use already needed it. Of the two major distributions for Windows, ActiveState and Strawberry, I eventually decided to go with Strawberry.

I uninstalled the version of Strawberry I had been using, installed a slightly newer version and wrote this page.


Installation

I downloaded the Microsoft Software Installer (MSI) version and installed that. Altogether the files take up a little under 1Gb of space.

I was not expecting quite so many files, .PL, .PM, .POD among them. PL files are Perl scripts, PM files are Perl Modules, a collection of scripts and functions, usually for a specific purpose. PM files for Perl can be gotten from the Comprehensive Perl Archive Network (CPAN). POD files are Plain Old Documentation files.


Windows Path Environment Variable

In order to find Perl for the PL files to run, the Windows path environment variable needs to be edited. On my system the following were added to the variable:

C:\perl\c\bin
C:\perl\perl\site\bin
C:\perl\perl\bin\

To test if these paths are correct, open a command prompt and type:

perl -v

This will give the Perl version number and some other information.


Apache Configuration

In Apache's httpd.conf file, to allow processing of Perl CGI sctipts I added the foloowing:

Options +Includes +ExecCGI

and

AddHandler cgi-script .cgi .pl

I do not envision using a lot of Perl scripts, so did not download and install mod_perl.

To test Apache is configure correctly, create a new text file containing the lines:

#!C:/Strawberry/perl/bin/perl.exe -T

use strict;
use warnings;

print "Hello World.\n";

Save the file as hello.pl and place in Apache's cgi-bin folder. Then, open a browser and navigate to your site's cgi-bin folder and add hello.pl. For example https://brisray.com/cgi-bin/hello.pl

The program should run and "Hello World" appear on the screen.


Perl Shebang

The shebang line in a Perl PL file is usually the first one and gives the locatation of the Perl interpreter along with any command line switches, such as

#!C:/Strawberry/perl/bin/perl.exe -T

Unlike Linux, Windows does not require the location of the Perl interpreter here but it will take notice of the switches.


Installed Modules

Perl's PM files are modules are a collection of related subroutines and variables that perform a task. Modules may be dependent on other modules being present to run.

Strawberry Perl includes a file named distributions txt that lists all 439 modules included with version 5.38.2.2-64bit

CPAN is a useful utility shell provided with Strawberry Perl. The full documentation is at Perldocs.

CPAN -a

cpan -a "creates a CPAN.pm autobundle", which is not very useful until you read the Snapshot.pm file it creates. Opening that file shows the lines

Bundle::Snapshot_2024_07_05_01 - Snapshot of installation on Fri Jul 5 12:58:25 2024
perl -MCPAN -e 'install Bundle::Snapshot_2024_07_05_01'

What it did was crete a snapshot of the installed modules which can then be used to reinstall the mdodules as they were when the command was run.

cpan -a > cpan-a.txt

Produces an interesting result. As well as the snapchot, the command produces a file like this:

Package namespace   installed   latest   in CPAN file
Algorithm::C3   0.11   0.11   HAARG/Algorithm-C3-0.11.tar.gz
Algorithm::Diff   1.201   1.201   RJBS/Algorithm-Diff-1.201.tar.gz
Alien::Build   2.83   2.83   PLICEASE/Alien-Build-2.83.tar.gz

The output contains a list of the modules along with version installed as well as the latest version on CPAN.

CPAN -l

cpan -l > cpan-l.txt

Produces a list all installed modules along with their versions:

alienfile   2.80
AppConfig   1.71
BerkeleyDB   0.65
CGI   4.60
Clone   0.46

CPAN -o

cpan -o > cpan-o.txt

Produces a list of outdated installed modules:

T/TO/TODDR/autodie-2.37.tar.gz
E/ET/ETHER/B-Hooks-EndOfScope-0.28.tar.gz
P/PJ/PJACKLAM/bignum-0.67.tar.gz
L/LE/LEEJO/CGI-4.66.tar.gz
P/PM/PMQS/Compress-Raw-Bzip2-2.212.tar.gz

@INC

When Perl is installed an array named @INC is created. This array contains the paths that Perl looks in to find the various modules. The array can be seen by using

perl -e "print \"@INC\""

or

perl -e "print qq(@INC)"

On my system both give C:/perl/perl/site/lib/MSWin32-x64-multi-thread C:/perl/perl/site/lib C:/perl/perl/vendor/lib C:/perl/perl/lib

Perl -V

will also display the contents of @INC along with other system information.

Perl Maven has an article explaining how to add paths to @INC.


CPAN Preferences

CPANs main configuraton file is in the lib\CPAN\config.pm file. The documentation to view and edit the file are at Perldocs.


Sources & Resources

ActiveState Perl
Apache Module mod_cgi (Apache)
Comprehensive Perl Archive Network (CPAN) - Source of Perl modules.
Dynamic Content with CGI (Apache)
How to change @INC to find Perl modules in non-standard locations (Perl Maven)
How to set the path and environment variables in Windows (Computer Hope)
Learn Perl
mod_perl (Apache)
Perl 101
Perl Beginners' Site
Perl Documentation
Perl News and Community
Perl Tutorials (Perl Maven)
Setting Up Perl Development Environment (Perl Tutorial)
Strawberry Perl
Testing Your Perl Installation (ThoughtCo)