PERL Basics

PERL Basics

The Practical Extraction and Report Language (PERL) was developed by Larry Wall. In Perl, Larry Wall invented a general-purpose tool which is at once a programming language and the mother of all filters. Perl is standard on Linux. However, it is free and executables are available for all UNIX flavors. For more details, log on to

Scalars and their operations

Scalars are primitive datatypes that can store numbers (usually stored in a double format, sometimes in integer form), strings and references.

Perl strings literals are delimited by either single or double quotes.

Single-quoted string literals cannot include escape sequences.

A null string can be ‘ ‘ or ” ”

A scalar type literal is specified by preceding the name with a $ symbol.

Rules to create variable names

The name must begin with a letter,

any number of letters, digits, or

underscore characters can follow,

Names are case sensitive.

By convention, names of variables in any programming language use only lowercase letters.

READ  PERL Basic Programs


$fname = “Vidyashri MH”;

fname is the name of the variable of type string and Vidyashri MH is the values of the variable. In this case, the string is created using double quotes.

$fname = ‘Vidyashri MH’;

fname is the name of the variable of type string andVidyashri MH is the values of the variable. In this case, the string is created using single quotes.

$number1 = 10;

number1 is the integer type variable with values 10.

$number2 = 10.10;

number2 is the double type variable with values 10.10.


A scalar variable that has not been assigned a value has the value undef (numeric value is 0; string value is the null string)

PERL Operators

Numeric Operators

Like traditional programming languages such as C, C++, Java, etc, PERL has all basic arithmetic operators,

addition +, subtraction -, multiplication *, division / and modulus %, Power Operator **, increment ++, decrement –.


Let, $num1 = 10, $num2 = 2.

READ  PERL Basic Programs


$sum = $num1 + $num2;

$dif = $num1 – $num2;

$mul = $num1 * $num2;

$div = $num1 / $num2;

$mod = $num1 % $num2;

$pow = $num1 ** 2;

String Operators

Catenation Operator – denoted by a period


If the value of $fruit is “mango”, the value of $fruit . “juice” is “mango juice”

Repetition operator – denoted by x


If the value of $greeting is “hello”, the value of $greeting x 3 is “hello hello hello”

A PERL program runs in a special interpretive mode, the entire script is compiled internally in memory before being executed. Unlike other interpreted language like the shell and awk, script errors are generated before execution itself.

For regular updates do like my facebook page VTUPulse