YouTip LogoYouTip

Perl Environment

Perl Environment Installation

Before we start learning the Perl language, we need to install the Perl execution environment first.

Perl can run on the following platforms:

  • Unix (Solaris, Linux, FreeBSD, AIX, HP/UX, SunOS, IRIX etc.)
  • Win 9x/NT/2000/
  • WinCE
  • Macintosh (PPC, 68K)
  • Solaris (x86, SPARC)
  • OpenVMS
  • Alpha (7.2 and later)
  • Symbian
  • Debian GNU/kFreeBSD
  • MirOS BSD
  • etc...

Many system platforms already have Perl installed by default. We can check if it is installed with the following command:

$ perl -v
This is perl 5, version 18, subversion 2 (v5.18.2) built for darwin-thread-multi-2level
(with 2 registered patches, see perl -V for more detail)
Copyright 1987-2013, Larry Wall
……

If the above information is output, it indicates that Perl is installed. If it is not installed, you can refer to the following installation guide.


Installing Perl

We can download the installation package for the corresponding platform from the official Perl website: https://www.perl.org/get.html

Image 1

Installing Perl on Unix and Linux

The steps to install Perl on Unix/Linux systems are as follows:

  • Open http://www.perl.org/get.html in a browser.
  • Download the source package suitable for Unix/Linux.
  • After downloading the perl-5.x.y.tar.gz file, execute the following operations.
$ tar -xzf perl-5.x.y.tar.gz
$ cd perl-5.x.y
$ ./Configure -de
$ make
$ make test
$ make install

Next, we can use the perl -v command to check if the installation was successful.

After a successful installation, the Perl installation path is /usr/local/bin, and the libraries are installed in /usr/local/lib/perlXX, where XX is the version number.

Installing Perl on Windows

On the Windows platform, there are ActiveState Perl and Strawberry Perl compilers.

The biggest difference between ActiveState Perl and Strawberry Perl is that Strawberry Perl includes more modules from CPAN, so the Strawberry Perl download file is over 80MB, while ActiveState Perl is only about 20MB.

We use Strawberry Perl here.

The steps to install Perl on Windows systems are as follows:

  • Strawberry Perl installation package link: http://strawberryperl.com.
  • Download the version corresponding to your system: 32-bit or 64-bit.
  • After downloading, double-click to open it and follow the installation wizard step by step.

Image 2

Installing Perl on Mac OS

Mac OS systems generally have Perl installed by default. If it is not installed, follow these steps:

  • Open http://www.perl.org/get.html in a browser.
  • Download the source package suitable for Mac OS.
  • After downloading the perl-5.x.y.tar.gz file, execute the following operations.
$ tar -xzf perl-5.x.y.tar.gz
$ cd perl-5.x.y
$ ./Configure -de
$ make
$ make test
$ make install

After successful execution, the Perl installation path is /usr/local/bin, and the libraries are installed in /usr/local/lib/perlXX, where XX is the version number.


Running Perl

Perl has different ways of execution.

1. Interactive Mode

We can execute Perl code directly in the command line. The syntax is as follows:

$perl -e <perl code> # Unix/Linux
or
C:>perl -e <perl code> # Windows/DOS

The command-line options are as follows:

Option Description
-d[:debugger] Run program under debugger
-Idirectory Specify @INC/#include directory
-T Enable taint checking
-t Enable taint warnings
-U Allow unsafe operations
-w Enable many useful warnings
-W Enable all warnings
-X Disable use warnings
-e program Execute Perl code
file Execute Perl script file

2. Script Execution

We can put Perl code in a script file and execute the file code with the following command:

$perl script.pl # Unix/Linux
or
C:>perl script.pl # Windows/DOS

Integrated Development Environment (IDE)

We can also execute Perl scripts in some graphical user interface (GUI) environments. Here are two commonly recommended Perl IDEs:

  • Padre: Padre is an integrated development environment for Perl language developers, providing syntax highlighting and code refactoring features.
  • EPIC: EPIC is a plugin for Perl Eclipse IDE. If you are familiar with Eclipse, you can use it.

Installation steps: Help-->Eclipse Marketplace-->Enter EPIC-->Select install and update.

Image 3

← Perl Data TypesPerl Tutorial β†’