It's a open source, general-purpose scripting language (supports cross platform) developed for text processing. Though now-a-days, it is used in different types of tasks, like web development, system administration, network programming, and many more.
Officially, Perl is not an acronym though it is known as Practical Extraction and Report Language.
It is a scipting language, as its interpreted not compiled. Unlike Python, it's a free-format language, hence, indentation is not mandatory. Though you are being suggested to follow any indentation rule to make this code readable.
Installation Procedure
Download Perl from it's official website https://www.perl.org.
If you are using Unix/Linux system, download the zip file and install the code according to the following instructions:
Once installation is done, you can issue
perl -v
command at $ prompt to check installation. If installation is
successful, it will display version information.
To install this software on Windows platform, you can download Strawberry Perl installation file from http://strawberryperl.com. Then install the file as you install other applications on Windows platform.
How to run Perl Script?
To start Perl coding in the interactive interpreter, you can write the code on terminal (on Unix/Linux)/command prompt (on Windows) as shown below.
Perl programs can be executed from a graphical user interface (GUI) environment, such as Padre. If you are familiar with Eclipse, you can also use Eclipse Plugin EPIC.
A Perl program consists of a sequence of declarations and statements, which run from the top to the bottom.
Let's try to test our first program as follows -
Let us try to write a program in a file and run it. Open a text
file
test.pl
and put the following lines inside your file.
Here
/usr/bin/perl
is actual the perl interpreter binary. If the installation location
is different, choose the proper location of the interpreter
library.
In this program, parenthesises are not mandatory, it's upto your chice. Try the following code.
Remember that a Perl file must be saved with a
.pl
or
.PL
file extension.
Comment Lines
Like other programming languages, in this programming language
#
is used for single line comment. For multi-line comment, the text
is placed between
=begin comment
and
=cut
. Check the following program.
Quotes in Perl
Both double or single quotes can be used in string literals as shown below
#!/usr/bin/perl print "Hello, world\n"; print 'Hello, world\n';
But these two are not equivalent. Double quotes can be used to interpolate special characters and variables. But single quotes can not be used for these. Check the following example
To work with multi-line string you can use the following technique.
Escape Character Sequences
Like most of the programming languages, Perl uses the backslash (\) character to escape any type of character, which may interfere code. Try the following code:
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.