0% found this document useful (0 votes)
19 views

What Is Perl?

Perl is a stable, cross-platform programming language created by Larry Wall in 1987. It is widely used for mission critical projects due to its extensive standard and third party libraries. Perl supports both procedural and object-oriented programming, and can interface with external libraries and databases. It is a flexible language that takes the best features from other languages like C, awk, sed, and sh.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

What Is Perl?

Perl is a stable, cross-platform programming language created by Larry Wall in 1987. It is widely used for mission critical projects due to its extensive standard and third party libraries. Perl supports both procedural and object-oriented programming, and can interface with external libraries and databases. It is a flexible language that takes the best features from other languages like C, awk, sed, and sh.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

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 in 1987.


Perl Features
• Perl takes the best features from other languages, such as C, awk,
sed, sh, and BASIC, among others.

• Perls database integration interface DBI supports third-party


databases including Oracle, Sybase, Postgres, MySQL and others.

• Perl works with HTML, XML, and other mark-up languages.

• Perl supports Unicode.

• Perl supports both procedural and object-oriented programming.

• Perl interfaces with external C/C++ libraries through XS or SWIG.

• Perl is extensible. There are over 20,000 third party modules available
from the Comprehensive Perl Archive Network (CPAN).

• The Perl interpreter can be embedded into other systems.


Sample Programs
• $perl -e 'print "Hello World\n"'
• print("Hello, world\n");
• print "Hello, world\n";
• # This is a comment in perl
• print "Hello
world\n";
# Output-> Hello
world
Sample Programs
print "Hello, world\n"; Hello, world
print 'Hello, world\n'; Hello, world\n$

$a = 10; Value of a = 10
print "Value of a = $a\n"; Value of a = $a\n$
print 'Value of a = $a\n';
Data Types
Scalar Scalars are simple variables. They are preceded by a dollar
sign ($). A scalar is either a number, a string, or a reference.
A reference is actually an address of a variable, which we
will see in the upcoming chapters.

Arrays Arrays are ordered lists of scalars that you access with a
numeric index, which starts with 0. They are preceded by an
"at" sign (@).

Hashes Hashes are unordered sets of key/value pairs that you access
using the keys as subscripts. They are preceded by a percent
sign (%).
# This is case of interpolation. Welcome to
$str = "Welcome to \n vishwaniketan!";
print "$str\n"; vishwaniketan!

# This is case of non-interpolation. Welcome to \nvishwaniketan!


$str = 'Welcome to \nvishwaniketan!';
print "$str\n";

# Only W will become upper case. Welcome to vishwaniketan!


$str = "\uwelcome to vishwaniketan!";
print "$str\n";
WELCOME TO
# Whole line will become capital. VISHWANIKETAN!
$str = "\UWelcome to vishwaniketan!";
print "$str\n"; Welcome to
# A portion of line will become capital. VISHWANIKETAN.edu!
$str = "Welcome to \Uvishwaniketan\E.edu!";
print "$str\n"; Welcome\ to\ vishwaniketan\'s\ family
# Backsalash non alpha-numeric including
spaces.
$str = "\QWelcome to vishwaniketan's family";
print "$str\n";
Scalar Variables
• $age = 25; # An integer assignment
• $name = "This is a Name String"; # A string
• $salary = 1445.50; # A floating point
• print "Age = $age\n";
• print "Name = $name\n";
• print "Salary = $salary\n";
• OUTPUT:-
• Age = 25
• Name = John Paul
• Salary = 1445.5
Array Variables
• @ages = (25, 30, 40);
• @names = ("A", "B", "V");
• print "\$ages[0] = $ages[0]\n";
• print "\$ages[1] = $ages[1]\n";
• print "\$ages[2] = $ages[2]\n";
• print "\$names[0] = $names[0]\n";
• print "\$names[1] = $names[1]\n";
• print "\$names[2] = $names[2]\n";

• OutPut:-
• $ages[0] = 25
• $ages[1] = 30
• $ages[2] = 40
• $names[0] = A
• $names[1] = B
• $names[2] = V
Hash Variables
• %data = ('A B', 45, 'CD', 30, 'PQR', 40);
• print "\$data{'A B'} = $data{'A B'}\n";
• print "\$data{'CD'} = $data{'CD'}\n";
• print "\$data{'PQR'} = $data{'PQR'}\n";

• Output:-
• $data{A B'} = 45
• $data{‘CD'} = 30
• $data{‘PQR'} = 40
Variable Context

• @names = ('A B', 'CD', 'PQR');


• @copy = @names;
• $size = @names;
• print "Given names are : @copy\n";
• print "Number of names are : $size\n";

• Output:-
• Given names are : A B DC PQR
• Number of names are : 3
Numeric Scalars
• $integer = 200;
• $negative = -300;
• $floating = 200.340;
• $bigfloat = -1.2E-23;
• # 377 octal, same as 255 decimal
• $octal = 0377;
• # FF hex, also 255 decimal
• $hexa = 0xff;
• print "integer = $integer\n";
• print "negative = $negative\n";
• print "floating = $floating\n";
• print "bigfloat = $bigfloat\n";
print "octal = $octal\n";
• print "hexa = $hexa\n";
• Output:-
• integer = 200
• negative = -300
• floating = 200.34
• bigfloat = -1.2e-23
• octal = 255
• hexa = 255
Loop
• for($i=1;$i<10;$i++)
{
printf("Iteration $i\n");
}
• $k=0;
while ($k<10) {
printf("Iteration $k\n");
$k++;
}

You might also like