Silk Web Hosting: Perl

Modified

The most recent release of Perl is available from the command-line and for web applications.

Modules

Perl modules can be installed into your own repository with the cpanm command. SAA will assist upon request if header files or required libraries are missing.

Set up a module environment in ~/perl5:

$ eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`
$ echo 'eval `perl -I ~/perl5/lib/perl5 -Mlocal::lib`' >> ~/.profile

Install a module with cpanm <modulename>.

Within your script:

# Add `~/perl5` to the `@INC` module include path
use local::lib;

# include the modules you have installed
use <modulename>;

Web applications

Scripts ending in .pl will be executed within a Perl CGI handler.

Example application

You can use the Mojolicious framework to create web applications of any size. The Lite version makes small applications particularly easy to create:

#!/usr/bin/perl
use Mojolicious::Lite;

get '/' => { text => 'Hello, world!' };

app->start;

Example basic CGI script

#!/usr/bin/perl
print("Content-Type: text/plain\n\n");

foreach $var (sort(keys(%ENV))) {
   $val = $ENV{$var};
   $val =~ s/\n/\\n/g;
   $val =~ s/"/\\"/g;
   print "${var}=\"${val}\"\n";
}