Copyright All rights reserved No part of this book may be reproduced, or stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without express written permission of the publisher. I would like to dedicate the book to the students who will be using it. I wish you future career success and hope you never stop learning. TABLE OF CONTENT
Introduction
Perl is a general-purpose programming language originally developed for text manipulation and now used for a wide range of tasks including system administration, web development, network programming, GUI development, and more.
What is Perl?
- Perl is a stable, cross platform programming language.
- Though Perl is not officially an acronym but few people used it as Practical Extraction and Report Language .
- It is used for mission critical projects in the public and private sectors.
- Perl is an Open Source software, licensed under its Artistic License , or the GNU General Public License (GPL) .
- Perl was created by Larry Wall.
- Perl 1.0 was released to usenet's alt.comp.sources in 1987.
- At the time of writing this tutorial, the latest version of perl was 5.16.2.
- Perl is listed in the Oxford English Dictionary .
PC Magazine announced Perl as the finalist for its 1998 Technical Excellence Award in the Development Tool category.
Perl Features
Perl and the Web
- Perl used to be the most popular web programming language due to its text manipulation capabilities and rapid development cycle.
- Perl is widely known as " the duct-tape of the Internet ".
- Perl can handle encrypted Web data, including e-commerce transactions.
- Perl can be embedded into web servers to speed up processing by as much as 2000%.
- Perl's mod_perl allows the Apache web server to embed a Perl interpreter.
- Perl's DBI package makes web-database integration easy.
Perl is Interpreted
Perl is an interpreted language, which means that your code can be run as is, without a compilation stage that creates a non portable executable program. Traditional compilers convert programs into machine language. When you run a Perl program, it's first compiled into a byte code, which is then converted ( as the program runs) into machine instructions. So it is not quite the same as shells, or Tcl, which are strictly interpreted without an intermediate representation. It is also not like most versions of C or C++, which are compiled directly into a machine dependent format.
Environment
Before we start writing our Perl programs, let's understand how to setup our Perl environment.
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 likely 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-linux Copyright 1987-2012, Larry Wall Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit. Complete documentation for Perl, including FAQ lists, 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. are available at the official website of Perl. are available at the official website of Perl.
Perl Official Website https://www.perl.org/ You can download Perl documentation from the following site. Perl Documentation Website https://perldoc.perl.org
Install Perl
Perl distribution is available for a wide variety of platforms. You need to download only the binary code applicable 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. Compiling the source code offers more flexibility in terms of choice of features that you require in your installation.
Unix and Linux Installation
Here are the simple steps to install Perl on Unix/Linux machine.
- Open a Web browser and go to https://www.perl.org/get.html.
- Follow the link 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. 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 libraries are installed in /usr/local/lib/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 like we have shown above.
Windows Installation
Here are the steps to install Perl on Windows machine.
- Follow the link for the Strawberry Perl installation on Windows http://strawberryperl.com
- Download either 32bit or 64bit version of installation.
- Run the downloaded file by double-clicking 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 supplied 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 https://www.perl.org/get.html .
- Follow the link 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 . 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 libraries are installed in /usr/local/lib/perlXX , where XX is the version of Perl that you are using.
Next page