Perl

The Perl interpreter is installed on all WebFaction servers.

On CentOS 6 servers (web300 and greater), Perl version 5.10.1 is installed. You can run the Perl interpreter as perl or perl5.10.1.

On CentOS 5 servers, Perl version 5.8.8 is installed. You can run the Perl interpreter as perl or perl5.8.8.

Installing cpanminus

We recommend using cpanminus to install CPAN modules. To install (or upgrade) cpanminus:

  1. Open an SSH session to your account.
  2. Switch to your ~/bin directory. Enter cd $HOME/bin and press Enter.
  3. Download cpanm. Enter wget http://xrl.us/cpanm and press Enter.
  4. Make cpanm executable. Enter chmod +x cpanm and press Enter.

cpanminus is now installed.

Installing a Perl Module with cpanm

To install a package with cpanm:

  1. If you have not already done so, install cpanminus.
  2. Open an SSH session to your account.
  3. Enter cpanm module, module is the name of the module to install, and press Enter. For example, to install Locale::gettext, enter cpanm Locale::gettext and press Enter.

The package is installed in ~/perl5.

Using Local Perl Modules in a Command-Line Script

To use a Perl module, the module’s path must appear in the @INC array, since Perl finds modules by searching the paths in the @INC array. When running command-line scripts, there are three ways to add paths to Perl’s module search:

  1. Use the Perl interpreter’s -I option to specify an additional search path.

    You can add one or more paths with one or more -I options followed by a path. Generally, run perl -I path script, where path is the path to a directory that contains a Perl module and script is the path to the Perl script itself.

    For example, to use a module installed in your home directory with cpanm, enter perl -I $HOME/perl5/lib/perl5/ script and press Enter.

  2. Use the use lib statement to specify an additional search path.

    You can add one or more paths with use lib statements. Insert use lib "path"; in your script on a line before other modules are used.

    For example, to use a module installed in your home directory with cpanm, insert use lib "/home/username/perl5/lib/perl5/"; in your script, where username is your username.

  3. Set the PERL5LIB environment variable.

    You can add one or more paths by setting the PERL5LIB environment variable in your shell. This is useful in cases where an executable Perl script is invoked directly (for example, running ./myscript.pl instead of perl ./myscript.pl), since the -I option is unavailable.

    • To add to PERL5LIB at run time, set the variable before invoking Perl, like this: enter PERL5LIB=$PERL5LIB:path perl script and press Enter.
    • To add to PERL5LIB for the duration a session, export the variable, like this: enter export PERL5LIB=$PERL5LIB:path and press Enter.
    • To add to PERL5LIB every time you login, add the export command to your .bashrc file, like this: enter echo "export PERL5LIB=$PERL5LIB:path" >> $HOME/.bashrc and press Enter.

    For example, to run a script using a module installed in your home directory with cpanm, enter PERL5LIB=$PERL5LIB:$HOME/perl5/lib/perl5/ perl script and press Enter.

Using Local Perl Modules in a CGI Script

To use a Perl module, the module’s path must appear in the @INC array, since Perl finds modules by searching the paths in the @INC array. When running as a CGI script, use the use lib statement to specify an additional search path.

You can add one or more paths with use lib statements. Insert use lib "path"; in your script on a line before other modules are used, where path is the path to a directory that contains a Perl module.

For example, to use a module installed in your home directory with cpanm, insert use lib "/home/username/perl5/lib/perl5/"; in your script, where username is your username.

Using Alternate Perl Versions with Perlbrew

Perlbrew is a tool that lets you install and run isolated versions of Perl from your home directory. You can use Perlbrew to install old, new, or upcoming versions of Perl.

Installing Perlbrew

To install Perlbrew:

  1. Open an SSH session to your account.
  2. Download and run the Perlbrew installation script. Enter curl -L http://install.perlbrew.pl | bash and press Enter.
  3. Follow the post-install instructions that appear in your terminal. You may need to modify a configuration file, such as .bash_profile, before continuing.
  4. Start a new SSH session.
  5. Confirm that Perlbrew has been installed. Enter perlbrew --version and press Enter.

If no errors appear, Perlbrew has been installed.

Using Perlbrew

After you have installed Perlbrew, you can install and select versions of Perl. To install and switch to a version of Perl:

  1. Open an SSH session to your account.

  2. Install a version of Perl. Enter perlbrew install --notest version, where version is a Perl version specifier, and press Enter.

    For example, to install the latest stable version of Perl, enter perlbrew install --notest stable and press Enter. Or to install a specific version, such as Perl 5.22.0, enter perlbrew install --notest 5.22.0 and press Enter.

  3. Wait for installation to complete. The installation process may take several minutes.

  4. Switch to the installed version of Perl. Enter perlbrew switch version, where version is the version number you installed previously, and press Enter.

The Perl version you selected is active. To verify your Perl selection, run perl --version. For more information on using Perlbrew, run perlbrew help.