Skip to content
Related Articles

Related Articles

Improve Article

Hello World Program in Perl

  • Last Updated : 11 Feb, 2019

Perl programming language is exclusively designed for text processing purposes. Its abbreviation denotes Practical Extraction and Report Language. It is compatible on various platforms, such as Windows, Mac OS, and almost all versions of UNIX.

Hello World! program in every programming language gives the beginner programmer a leap in proceeding further in the new language. The basic Hello world program just gives the output by printing ” Hello World!” on the screen. In Perl, a basic program consists of the following steps of execution,

Step 1: Transfer the file to Perl Interpreter:
Always in Perl, the first line starts with a pair of characters #!. It insists Perl interpreter how the file should be executed. Here, the file should be transferred to Perl interpreter that resides in /usr/bin/perl folder. So, the first line of the program will go this way,

#!/usr/bin/perl

Step 2: Pragma in Perl:
A pragma is a specific module in Perl package which has the control over some functions of the compile time or Run time behavior of Perl, which is strict or warnings. So the next two lines go like this,

use strict;
use warnings;

Step 3: Use of print() function:
Lastly displaying the output, We use print() function to display a string in perl.



print("Hello World\n");

Code:




#!/usr/bin/perl
  
# Modules used
use strict;
use warnings;
  
# Print function 
print("Hello World\n");

Output:

Hello World

 
Important Points:

  • The file must be stored with an extension of .pl
  • Directory of the Perl Package must be same as to where the Program file is saved.

How to Run a Perl Program?

Generally, there are two ways to Run a Perl program-
  • Using Online IDEs:You can use various online IDEs which can be used to run Perl programs without installing.
  • Using Command-Line:You can also use command line options to run a Perl program. Below steps demonstrate how to run a Perl program on Command line in Windows/Unix Operating System:
     
    Windows
    • First, open a text editor like Notepad or Notepad++.
    • Write the code in the text editor and save the file with .pl extension
    • Make sure you have downloaded and installed the latest version of Perl from https://www.perl.org/get.html
    • Open commandline and Run the command perl -v to check if your Perl’s latest version has been installed properly or not.
    • To compile the code type perl HelloWorld.pl. If your code has no error then it will execute properly and output will be displayed.

    Unix/Linux
    • Follow the upgiven steps for writing code and saving the file with .pl extension
    • Open Terminal of your Unix/Linux OS and follow the following steps to download and install Perl:
    • Now, run the command perl -version to make sure if your Perl’s latest version has been installed properly or not.
    • To compile the code type perl hello.pl. If your code has no error then it will execute properly and output will be displayed.
My Personal Notes arrow_drop_up
Recommended Articles
Page :