Mint

How to Create and Run a Perl Script in Linux Mint 20

Create and Run a Perl Script in Linux Mint 20

Introduction:

Perl is an efficient high-level programming language that was released in 2000 and has been extensively used since then. It stands for Practical Extraction and Reporting Language. The feature of Perl that makes it extremely versatile is that it can be used across multiple platforms including Linux. In today’s article, we would be sharing with you the method of creating and running a Perl script in Linux Mint 20.

Some Pre-Processing:

Before we take a look at the procedure of creating and running a Perl script in Linux Mint 20, we would like to install Perl on our Linux Mint 20 system with the help of the following command:

sudo apt-get install perl

In our case, we already had Perl installed on our Linux Mint 20 system. That is why we have received the messages shown in the image below. However, if Perl would not have been installed on our system, then running this command would have immediately installed it.

Now we would like to check out the version of Perl installed on our system by running the following command:

perl --version

The version of Perl installed on our Linux Mint 20 system is shown in the image below:

After this, we also need to ensure that the respective interpreter for Perl is also installed on our Linux Mint 20 system. We can do this by running the following command:

which perl

The output of this command will reveal the path to the binary file of the Perl interpreter as shown in the image below:

You can also check out the path to the source file and man pages of the Perl interpreter with the help of the following command:

whereis perl

The output of this command will guarantee the presence of the Perl interpreter on our Linux Mint 20 system as shown in the image below:

Now we are all set to write and run our first Perl script in Linux Mint 20.

Method of Creating a Perl Script in Linux Mint 20:

For creating a sample Perl script in Linux Mint 20, we will run the following command:

sudo nano Sample.pl

Here, you can replace Sample with any name of your choice that you want to keep for your first Perl script. We have named it as MyPerlScript.pl as shown in the image below:

This command will open an empty Perl file with the nano editor. We have written a simple Perl script to display a message on the terminal as shown in the following image. Here, the first line of the script is mandatory and it is written to indicate that the said file is a Perl file. Then we have simply written the “print” command followed by a sample message which will be displayed on the terminal. After that, we have closed this file once it was saved.

Method of Running a Perl Script in Linux Mint 20:

After creating our first Perl script in Linux Mint 20, now it is the time to execute it with the following command:

perl Sample.pl

Here, you can replace Sample with the name of your particular first Perl script. The name of our first Perl script was MyPerlScript.pl as shown in the image below:

After running this command, the output of our created Perl script will be displayed on the terminal as shown in the following image:

Conclusion:

This article focused on the creation and execution of a Perl script in Linux Mint 20. Moreover, if Perl is not installed on your system already, then we have even shared with you the method of installing it on your system and also ensuring if its interpreter exists there or not.

Similar Posts