Friday, January 20, 2012

Learning PERL | Day 1

Hello Friends! I spent a long, long time in advancing my knowledge over PERL-the most amazing programming language to deal with. I usually saw new programmers worrying much about dealing with PERL, they treat it as a threat to learn after seeing it's 1300-1400 paged books. Since, I learned it in a slight different way, and find it enjoying, I think I should spread the words out here in my daily blog.

In my this daily basis learning blog, I will introduce the basics of PERL programming language and it's my humble belief that if you visit and read this blog course-ware daily, you will learn PERL in an easiest and enjoyable way. The notes you get from here will help you understanding PERL basics which can help you in your homework, in college studies and in many day-to-day tasks in programming because PERL is everywhere.


So, let us start with the introduction of PERL first. PERL is a programming language created in 1987. It stands for Practical Extraction and Report Language. First of all, on our first learning day, please note that you will need to download PERL to run its programs on your computer. Mostly, if you are using your college computer, there is a possibility that it is already installed there, since, it is widely used as a learning tool. In case, you find it is not there, you can download its free copy from PERL website.


Let’s start our day 1 of programming. To write a PERL program, you need a text editor, for which I recommend notepad++, which is downloadable for free from Notepad++ website. I recommend using notepad++ because it offers many additional features like helping you in commands, different colors for variables and keywords etc., which may help you recognizing your program easily. Alternatively, you can use notepad also. Please note that using word processing software like Microsoft Word can produce unexpected results since they add formatting data to your codes. So, it is not suggested to use any word processing software. Also, I recommend saving your PERL codes with “.pl” extension. Although it is not necessary to do so because PERL won’t bother about filename extensions, but, in this way it looks nice and also some operating systems does not allow saving a file without any extension.

So, let us start with the simplest program on our first day. It is, addition of two numbers. The source code of this program is:

$x = 100;
$y = $x + $x;
print $y;

Type the code fragment given above in notepad++ and save it under filename “SimpleAddition.pl”.

Now, let us understand what the symbols used in above code means.

$x and $y are known as variables and are used for storing data in the program. You can understand them as initially empty baskets. Although, they may contain garbage values if you do not initialize them with any finite values first.
Our second line of code, “$y = $x + $x;” means “put the value of ($x + $x) in $y”. This is the main formula of our program.
Lastly, there is “print $y” which means “print whatever contained in $y”.
Also, you might have noticed that we have put a semicolon “;” after every line. It is used to terminate a particular statement and is known as terminator.

Well, so, till now we have written a basic addition code in PERL. Let us check if our program gives an expected output. To get the output, run the program by commanding “perl SimpleAddition.pl”, which should return you value “200”. Since, we do not define the preciseness we need in our program, in some systems, the output may be like “200.00000000000”.

So, that’s over for today. Today we learn some basics of writing a program in PERL and tried a simple program. Well, you know, this is a good start for your first day as a beginner. In my next blogs, I will tell you about how to write more complex and tricky programs and some more basics of PERL.

Hope you find this blog learning session enjoyable. In case you have further query, please feel free in posting your comment.

With Warm Regards,
Yajur Kumar
(PERL Programming Expert)

2 comments:

  1. Excellent Blog, I like your blog and It is very informative. Thank you
    ReactJs
    React Native

    ReplyDelete
  2. Nice blog, very informative content.Thanks for sharing, waiting for the next update…
    Skills needed for digital marketing
    Digital Marketing required skills

    ReplyDelete