6/10/2014 Introduction to PERL Programming
Introduction to PERL Programming
What is Perl?
Perl is a programming language especially
designed for text editing. It is now widely used
for a variety of purposes including Linux system
administration, network programming, web
development etc.
Perl is of great importance in a Linux operating
system where it can be used to create programs,
handle Databases and e-mails, GUI (Graphical
User Interface) development, Networking and
System Administration.
Please be patient . Video will load in some time. If you still face issue viewing video click here
PERL V/s Shell Scripting
[Link] 1/5
6/10/2014 Introduction to PERL Programming
Even though, shell scripting is available to programmers, they prefer Perl because:
Programming on Perl does not cause portability issues, which is common when using different
shells in shell scripting.
Error handling is very easy on Perl
You can write long and complex programs on Perl easily due to its vastness. This is in contrast
with Shell that does not support namespaces , modules , object , inheritance etc.
Shell has fewer reusable libraries available . Nothing compared to Perl's CPAN
Shell is less secure. Its calls external functions(commands like mv , cp etc depend on the shell
being used) . On the contrary PERL does useful work while using internal functions.
Perl Basics
Always start your script with
#!/usr/bin/perl
It directs the execution to Perl interpreter on your system.
The path is usually the same on most of the Linux distributions.
[Link] 2/5
6/10/2014 Introduction to PERL Programming
Storing Variables, Input and Output
Action Description Syntax Example
Defining Storing values $variable $name =
a to a Variable in = "Ronald";
Variable form of string "value";
value and number
Output If you want a print Print("thanks")
in Perl string or a value ("value
to display on the to be
screen then you printed")
can use the print ;
command
Input in If you want a use $variable $username = ;
Perl input to be =;
assigned to a
variable use
Important points
With this, if you want the Perl interpreter to ignore a statement, prefix it with a # symbol.
Remember that every statement in Perl ends with asemi-colon.
Perl is case-sensitive . Make sure you use the right case.
You can use any text editor to write your PERL scripts.
You should then save the script file in .pl extensionwhich will make it recognizable.
Make sure you do not use spaces when you are naming the Perl script file.
[Link] 3/5
6/10/2014 Introduction to PERL Programming
Creating a PERL Script
Let us understand the steps in creating a PERL Script
1. Create a file using a vi editor(or any other editor). Name script file with extension .pl
2. Start the script with #! /bin/perl
3. Write some code.
4. Save the script file as [Link]
5. For executing the script type perl [Link]
Let's write a PERL script which will take input from the user and display it back through the script.
#!/usr/bin/perl
print("May I take your name please?") ;
$name = ;
print("Thank you $name");
Let's see the steps to create this script -
[Link] 4/5
6/10/2014 Introduction to PERL Programming
Summary:
Perl is a general-purpose programming language originally developed for text manipulation
Now used for a wide range of tasks including system administration, web development, network
programming, GUI development, and more.
Perl files have .pl extension
There are three types of variables in Perl, Scalar, Lists and Hashes.
[Link] 5/5