Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Perl Environment Installation

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:

Perl is already installed by default on many system platforms; we can check whether 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 means it is installed; if not yet installed, you can look at the installation instructions below.


Installing Perl

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

Installing Perl on Unix and Linux

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

$ tar -xzf perl-5.x.y.tar.gz $ cd perl-5.x.y $ ./Configure -de $ make $ make test $ make install

Next, if we perl -v command to check whether 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, Perl has the ActiveStatePerl and Strawberry Perl compilers.

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

Here we use Strawberry Perl.

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

Installing Perl on Mac OS

Perl is generally installed by default on Mac OS systems; if it is not installed, perform the following steps:

$ 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 on the command line; the syntax format is as follows:



$perl  -e            # Unix/Linux



或 



C:>perl -e           # Windows/DOS

The command-line parameters are as follows:

Option Description
-d[:debugger] Run the program in debug mode
-Idirectory Specify the @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 a Perl script file

2. Script execution

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



$perl  script.pl          # Unix/Linux



或 



C:>perl script.pl         # Windows/DOS

Integrated Development Environment (IDE: Integrated Development Environment)

We can also execute Perl scripts in some Graphical User Interface (GUI) environments. The following two commonly used Perl integrated development environments are recommended: