Steps to Create and run a Perl script in CentOS 8 ?

Are you trying to install Perl script in CentOS 8 ?

This guide is for you.


Perl programming is a general-purpose language that is mainly developed for text manipulation but, now this is used for a wide range of functions including web development, system administration, network programming, graphical user interface development, and more others.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to install Packages on their CentOS Server.

In this context, we shall look into how to install Perl on CentOS 8.


More information about Perl ?

Perl language is intended to design to be practical rather than beautiful displaying features like minimal, elegant, and tiny. This programming language is complete and efficient. The major features of Perl are easy to use, supports object-oriented (OO) and procedural programming languages, and has built-in support for processing text. 

The most impressive feature of Perl is that it supports a large collection of third-party modules.


How to install Perl on CentOS 8 ?

To begin, you need to log into your Server as the root user via an SSH tool such as putty.

and then follow the steps given below:


i. In the CentOS 8 Linux distribution, the Perl package is already included. By using the following command you can also check the availability of Perl package:

$ sudo yum info perl

ii. Then, check the installation of Perl packages on your system by running the command below:

$ sudo rpm -qa | grep perl

iii. If Perl is not preinstalled then, first you need to install Perl. By typing the following command with sudo privileges, you can install Perl on CentOS 8:

$ sudo yum install perl

iv. Once the Perl configurations are successfully completed on your CentOS 8 system, you can check which version of Perl is installed on your machine:

$ perl –v


How to Create and Run Perl Script on CentOS 8 ?

You can run a Perl script by using the following two different methods:


1. Creating a Perl file

a. Create a text file by using your text editor and paste the following code in this file:

#!/usr/bin/perl
print “my first Test Perl Script !\n”;

b. Save the above file with the name ‘testprogram.pl’ on your system. The use of ‘.pl’ extension with file name represents that this is Perl language Script. In the above program, it will print the text 'my first test perl script' on the terminal while you will execute the script.

The '\n' is used to move your cursor on the next line of the terminal after displaying the above message. Run the Perl Script by using the following command:

$ perl testprogram.pl

Also, you can also run the above script by typing the following commands:

$ chmod +x testprogram.pl
$ ./testprogram.pl
my first Test Perl Script!

2. Execute directly using Terminal

You can also execute the Perl command directly by using the terminal.

For example, we want to print the same message on the terminal without creating a text file. In this case, using the following command you can do this:

$ perl -e ‘print “my first Test Perl Script!!\n"'

The following output will print on your terminal after running the above mentioned command.


[Need urgent assistance to install Perl on your Server? We are available to help you.]

This article will guide you on steps to perform Perl installation on #CentOS 8. You will also learn how to create and execute the #Perl #script on your CentOS system by using the terminal #commands.

Perl is a programming language that can be used to perform tasks that would be difficult or cumbersome on the command line.

To run a Perl script in Linux:

1. Run the "perl" command with the Perl script included in the command line.

2. Run the "perl" command with the Perl script supplied from the standard input stream.

3. Run the "perl" command with the Perl script supplied in a file.

4. Run Perl script files as commands.

Related Posts