Perl Environment Installation
Before we start learning Perl, we need to install the Perl execution environment.
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
- and more...
Many system platforms come with Perl pre-installed. We can check if it is installed by running 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 you see the above output, it means Perl is installed. If not, follow the installation instructions below.
Installing Perl
You can download the installation package for your platform from the official Perl website: https://www.perl.org/get.html
Unix and Linux Installation of Perl
The steps to install Perl on Unix/Linux systems are as follows:
- Open http://www.perl.org/get.html in your browser.
- Download the source package for Unix/Linux.
- After downloading the perl-5.x.y.tar.gz file, perform the following operations:
$ tar -xzf perl-5.x.y.tar.gz $ cd perl-5.x.y $ ./Configure -de $ make $ make test $ make install
Next, check if the installation was successful by running the perl -v command.
After successful installation, Perl will be located at /usr/local/bin, and the libraries will be installed in /usr/local/lib/perlXX, where XX is the version number.
Windows Installation of Perl
Perl has ActiveStatePerl and Strawberry Perl compilers for the Windows platform.
The main difference between ActiveState Perl and Strawberry Perl is that Strawberry Perl includes more modules from CPAN, so the Strawberry Perl installation file is about 80MB, while ActiveState Perl is around 20MB.
We will use Strawberry Perl here.
The steps to install Perl on Windows are as follows:
- Download the Strawberry Perl installer from http://strawberryperl.com.
- Download the version corresponding to your system: 32-bit or 64-bit.
- Double-click the downloaded file and follow the installation wizard.
Mac OS Installation of Perl
Mac OS systems typically come with Perl pre-installed. If it is not installed, follow these steps:
- Open http://www.perl.org/get.html in your browser.
- Download the source package for Mac OS.
- After downloading the perl-5.x.y.tar.gz file, perform 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, Perl will be located at /usr/local/bin, and the libraries will be installed in /usr/local/lib/perlXX, where XX is the version number.
Running Perl
Perl can be executed in different ways.
1. Interactive Mode
You can execute Perl code directly in the command line with the following syntax:
$ 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 in debugger |
-Idirectory | Specify @INC/#include directory |
-T | Enable taint checks |
-t | Enable taint warnings |
-U | Allow unsafe operations |
-w | Enable useful warnings |
-W | Enable all warnings |
-X | Disable all warnings |
-e program | Execute Perl code |
file | Execute Perl script file |
2. Script Execution
You can place Perl code in a script file and execute it with the following command:
$ perl script.pl # Unix/Linux
or
C:> perl script.pl # Windows/DOS
Integrated Development Environment (IDE)
You can also execute Perl scripts in some graphical user interface (GUI) environments. Here are two recommended Perl IDEs:
- Padre: Padre is an IDE for Perl developers, providing syntax highlighting and code refactoring features.
- EPIC: EPIC is a Perl plugin for the Eclipse IDE. If you are familiar with Eclipse, you can use it.
Installation steps: Help --> Eclipse Marketplace --> Enter EPIC --> Select and install.