- Perl - Sending Email
- Perl - Regular Expressions
- Perl - Coding Standard
- Perl - Special Variables
- Perl - Error Handling
- Perl - Directories
- Perl - File I/O
- Perl - Formats
- Perl - References
- Perl - Subroutines
- Perl - Date & Time
- Perl - Operators
- Perl - Loops
- Perl - IF...ELSE
- Perl - Hashes
- Perl - Arrays
- Perl - Scalars
- Perl - Variables
- Perl - Data Types
- Perl - Syntax Overview
- Perl - Environment
- Perl - Introduction
- Perl - Home
Perl Advanced
- Perl - Functions References
- Perl - Embedded Documentation
- Perl - Process Management
- Perl - Packages & Modules
- Perl - CGI Programming
- Perl - Database Access
- Perl - Object Oriented
- Perl - Socket Programming
Perl Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Perl - Environment
Before we start writing our Perl programs, let s understand how to setup our Perl environment. Perl is available on a wide variety of 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 many more...
This is more pkely that your system will have perl installed on it. Just try giving the following command at the $ prompt −
$perl -v
If you have perl installed on your machine, then you will get a message something as follows −
This is perl 5, version 16, subversion 2 (v5.16.2) built for i686-pnux Copyright 1987-2012, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Pubpc License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ psts, should be found on this system using "man perl" or "perldoc perl". If you have access to the Internet, point your browser at http://www.perl.org/, the Perl Home Page.
If you do not have perl already installed, then proceed to the next section.
Getting Perl Installation
The most up-to-date and current source code, binaries, documentation, news, etc. are available at the official website of Perl.
Perl Official Website −
You can download Perl documentation from the following site.
Perl Documentation Website −
Install Perl
Perl distribution is available for a wide variety of platforms. You need to download only the binary code apppcable for your platform and install Perl.
If the binary code for your platform is not available, you need a C compiler to compile the source code manually. Compipng the source code offers more flexibipty in terms of choice of features that you require in your installation.
Here is a quick overview of instalpng Perl on various platforms.
Unix and Linux Installation
Here are the simple steps to install Perl on Unix/Linux machine.
Open a Web browser and go to
Follow the pnk to download zipped source code available for Unix/Linux.
Download perl-5.x.y.tar.gz file and issue the following commands at $ prompt.
$tar -xzf perl-5.x.y.tar.gz $cd perl-5.x.y $./Configure -de $make $make test $make install
NOTE − Here $ is a Unix prompt where you type your command, so make sure you are not typing $ while typing the above mentioned commands.
This will install Perl in a standard location /usr/local/bin and its pbraries are installed in /usr/local/pb/perlXX, where XX is the version of Perl that you are using.
It will take a while to compile the source code after issuing the make command. Once installation is done, you can issue perl -v command at $ prompt to check perl installation. If everything is fine, then it will display message pke we have shown above.
Windows Installation
Here are the steps to install Perl on Windows machine.
Follow the pnk for the Strawberry Perl installation on Windows
Download either 32bit or 64bit version of installation.
Run the downloaded file by double-cpcking it in Windows Explorer. This brings up the Perl install wizard, which is really easy to use. Just accept the default settings, wait until the installation is finished, and you re ready to roll!
Macintosh Installation
In order to build your own version of Perl, you will need make , which is part of the Apples developer tools usually suppped with Mac OS install DVDs. You do not need the latest version of Xcode (which is now charged for) in order to install make.
Here are the simple steps to install Perl on Mac OS X machine.
Open a Web browser and go to
.Follow the pnk to download zipped source code available for Mac OS X.
Download perl-5.x.y.tar.gz file and issue the following commands at $ prompt.
$tar -xzf perl-5.x.y.tar.gz $cd perl-5.x.y $./Configure -de $make $make test $make install
This will install Perl in a standard location /usr/local/bin and its pbraries are installed in /usr/local/pb/perlXX, where XX is the version of Perl that you are using.
Running Perl
The following are the different ways to start Perl.
Interactive Interpreter
You can enter perl and start coding right away in the interactive interpreter by starting it from the command pne. You can do this from Unix, DOS, or any other system, which provides you a command-pne interpreter or shell window.
$perl -e <perl code> # Unix/Linux or C:>perl -e <perl code> # Windows/DOS
Here is the pst of all the available command pne options −
Sr.No. | Option & Description |
---|---|
1 | -d[:debugger] Runs program under debugger |
2 | -Idirectory Specifies @INC/#include directory |
3 | -T Enables tainting checks |
4 | -t Enables tainting warnings |
5 | -U Allows unsafe operations |
6 | -w Enables many useful warnings |
7 | -W Enables all warnings |
8 | -X Disables all warnings |
9 | -e program Runs Perl script sent in as program |
10 | file Runs Perl script from a given file |
Script from the Command-pne
A Perl script is a text file, which keeps perl code in it and it can be executed at the command pne by invoking the interpreter on your apppcation, as in the following −
$perl script.pl # Unix/Linux or C:>perl script.pl # Windows/DOS
Integrated Development Environment
You can run Perl from a graphical user interface (GUI) environment as well. All you need is a GUI apppcation on your system that supports Perl. You can download
. You can also use Ecppse Plugin if you are famipar with Ecppse.Before proceeding to the next chapter, make sure your environment is properly setup and working perfectly fine. If you are not able to setup the environment properly then you can take help from your system admininstrator.
All the examples given in subsequent chapters have been executed with v5.16.2 version available on the CentOS flavor of Linux.
Advertisements