How To Write and Execute Perl Program to print Hello World

Perl Hello World Example: How To Write and Execute Perl Program to print Hello World



Following article is about writing a simple Hello World program in Perl. It includes writing and executing Perl program. Before starting with the program to print Hello World String, I would like to add few key things about Perl Script. First is Perl stands for Practical Extraction and Report Language and used widely in critical projects in both public and private sectors. Second is Perl is a interpreted language we will see what it means as we explore further.
Lets see step by step guide to write Simple Perl program to print Hello World :
To run the Perl program we need Perl interpreter to be installed on the machine. To check whether it is installed on the machine type the following commands as shown in image






If you don't find Perl installed on your machine then you can use yum to install the Perl you just need to do yum install Perl which will install Perl.

Next step is to write a Perl program to print Hello World.
To write the HelloWorld script use following command
vim HelloWorld.pl 

First line will be the path of the interpreter which we found using the commands shown above. This tells the system to use the /usr/bin/perl interpreter to execute the script.
Second line is the comment which start with hash #
Third line is where we are actually printing the Hello World String using print command as shown below :

Hello World Example in Perl



#!/usr/bin/perl 
# Perl program to print Hello World 
print "Hello World"; 


Perl is interpreted language so we don’t have a compilation step as C or Java. we need to directly execute the Perl script. When you run a Perl program, it gets first compiled into a bytecode, and as the program runs it is converted to machine instructions.
To execute the above program we need to call perl [filename]
i.e.

perl HelloWorld.pl 


to change the permission of the program we can use chmod +x command.
Share on Google Plus

About Pranav

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment