Perl stands for â€œPractical Extraction and Report Languageâ€? and it named so because of its typical use in extracting information from a text file and printing out report for converting a text file into another form.
But now it is widely used for a wide range of tasks including system administration, web development (Perl CGI is used) , network programming, GUI development and many more.
Note: â€œPerlâ€? with a capital P refers to the language and â€œperlâ€? with a lowercase p refers to the actual interpreter that compiles and runs your program.
Have you ever thought of why the â€œPerlâ€? is not written in all caps, its because the Perlâ€™s creator Larry Wall came up with the name first and expansion later. So, it is actually backronym, not an acronym.
Perl is an interpretive language which means that the code is not required to be converted to byte code and then run the byte code. Perl interpreter can run the Perl direct source code.
Other languages like Java where the source code need to be converted to byte code and then that byte code file is executed. This is known as Compiled implementation.
Perl program to print "Hello World"??
Line 1: #!/usr/bin/perl Line 2: use strict; Line 3: use warnings; Line 4: print "Hello, world!\n";
Explanation of each line:
Line 1: This is known as
shebangor she-bang or sh-bang# character is the Perl comment character. It tells the system that the line is not an executable instruction.
! character is a special character; it indicates what type of program this is.
/usr/bin/perl is the location of the Perl executable on your system. This executable interprets your program; in other words, it figures out what you want to do and then does it. Because the Perl executable has the job of interpreting Perl instructions, it usually is called the Perl interpreter.
use strict; it's a safety net, Perl by default is very forgiving so to make it robust it is recommended to start every program with this line. It is pragma which disables certain Perl expressions that could behave unexpectedly or are difficult to debug, turning them into errors.
For example, if the variable is not declared with my keyword it will throw error.
use warnings; It is pragma which gives control over warnings.
Note : Except the comment line all the other lines are ended up with the semi colon ; (Perl statement ends in a semi colon) Save the above program with .pl extension. For example :
How to execute it in Unix?
chmod 755 Hello.pl
perl -c Hello.pl
Note: It will only check the syntax of the program.
perl Hello.pl or ./Hello.pl
The above program can be written in one line as well:
perl -e â€˜print â€œHello World \nâ€?;â€™
-e is used to take the Perl statements through command line and execute it.
Myself KarthiQ, I am the author of this blog, I know ways to write a good article but some how I donot have the skills to make it to reach people, would you like help me to reach more people By sharing this Article in the social media.