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.
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.
In this article, we will guide you about the Perl installation on CentOS 8. We will also talk about how to create and execute the Perl script on your CentOS system by using the terminal commands.
You should be logged in from an administrator or root account on your system.
Install Perl on CentOS 8
Access the terminal window. To do so, click on the ‘Activities’ and then choose ‘Terminal’ application from the all left sidebar applications. 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
Now, by typing the following command you will check the installation of Perl packages on your system:
$ sudo rpm -qa | grep perl
On our system the Perl packages are already installed. 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
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
Create and Run Perl Script on CentOS 8
You can run a Perl script by using the following two different methods:
Method 1: Creating a Perl file
Create a text file by using your text editor and paste the following code in this file:
print “my first Test Perl Script !\n”;
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
Or you can also run the above script by typing the following commands:
$ chmod +x testprogram.pl
my first Test Perl Script!
Method 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:
Today, we learned about the Perl installation in this article and how to execute a Perl Script on CentOS 8. We have executed various commands on the terminal for running a Perl Script. Moreover, you can also install and configure the necessary Perl modules by using the ‘yum’ package manager. You can tell us about your queries through the comments.