Introduction to Perl
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
- Wait...
- Perl has been installed by default on many system platforms. We can check whether it has been 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 the above information is output, Already installed, if not installed yet, you can see the following installation instructions.
Installing PerlWe can download the installation package for the corresponding platform from Perl’s official 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:
- Open http://www through a browser .perl.org/get.html.
- 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 we run the
command to see if the installation is successful. After successful installation, the installation path of Perl is
/usr/local/bin, and the library is installed in /usr/local/lib/perlXX, XX is the version number . Window Installation Perl
Perl has ActiveStatePerl and Strawberry Perl compilers on the Window platform.
The biggest difference between ActiveState Perl and Strawberry Perl is that Strawberry Perl contains many modules from CPAN, so the installation file downloaded by Strawberry Perl is more than 80M, while ActiveState Perl is only about 20M.
We use Strawberry Perl here.
The steps to install Perl on Window systems are as follows:
- Strawberry installation package link: http://strawberryperl.com.
- Download the version corresponding to your system: 32bit or 64bit.
- After downloading, double-click to open it and follow the installation wizard step by step to install it.
Mac OS Install Perl
Mac OS system generally has Perl installed by default. If it is not installed, perform the following steps:
- Open http://www.perl.org/get.html through the browser.
- Download the source code 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, the installation path of Perl is
, and the library is installed in /usr/local/lib/perlXX, XX is the version number.
Running PerlPerl has different execution methods.
1. Interactive
We can execute perl code directly in the command line. The syntax format is as follows:
$perl -e <perl code> # Unix/Linux 或 C:>perl -e <perl code> # Windows/DOS
The command line parameters are as follows:
Options | Description |
---|---|
-d[:debugger] | Run the program in debug mode |
-Idirectory | Specify @INC/#include directory |
-T | Allow contamination detection |
-t | Allow taint warnings |
-U | Allow unsafe operations |
-w | Allow many useful warnings |
-W | Allow all warnings |
-X | Disable usage warning |
-e program | Execute perl code |
file | Execute perl script file |
2. Script execution
We can put the perl code in the script file , execute the file code through 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 on some graphical user interface (GUI) environments. The following are two commonly used Perl integrated development environments recommended:
Padre: Padre is an integrated development environment for Perl language developers, providing syntax highlighting and code refactoring functions.
EPIC: EPIC is a plug-in for the Perl Eclipse IDE. If you are familiar with Eclipse, you can use it.
Installation steps: Help-->Eclipse Marketplace-->Enter EPIC--> Select install and update.
<img src="http://php.cn/style/images/20150311184626567.png"