Create and Run a Perl Script in Linux Mint - How to perform this task ?

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.

Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Linux Mint related queries.

In this context, we shall look into the method of creating and running a Perl script in Linux Mint 20.

How to install Perl in Linux Mint 20 ?

i. It is important to install Perl on our Linux Mint 20 system before performing the procedure of creating and running a Perl script.

To do this, execute the command below:

$ sudo apt-get install perl

ii. Now, you can check out the version of Perl installed on our system by running the following command:

$ perl --version

iii. 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.

iv. 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.

Next, we will write and run our first Perl script in Linux Mint 20.

How to create a Perl Script in Linux Mint 20 ?

In order to create a sample Perl script in Linux Mint 20, we will run the following command:

$ sudo nano

This command will open an empty Perl file with the nano editor. You can then write a simple Perl script to display a message on the terminal. 

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.

Just as shown below:

print "Hello World! I have just created a sample perl script \n";

How to run 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

Here, you can replace Script_name with the name of your particular first Perl script. 

After running this command, the output of our created Perl script will be displayed on the terminal.

[Need urgent assistance to fix missing packages in Linux Mint? We are available to help you today. ]

This article covers how to create and execute 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.

Perl is a programming language that can be used to perform tasks that would be difficult or cumbersome on the command line. Perl is included by default with most GNU/Linux distributions. 

PERL- Practical Extraction and Reporting Language (not an official acronym), is a stable and cross-platform language and was created by Larry Wall. 

Perl is an open source, general-purpose, interpreted language. Programs written in Perl are called Perl scripts. 

Perl supports both Procedural language and Object Oriented language and has powerful built-in support for text processing and have a collection of third-party modules. Perl language is mainly used for Web Applications, System Administration, Batch Processing, Applications which involving text processing and most command line applications. 

To run a Perl script in Unix:

1. Find the interpreter/executors path. In this case its /usr/bin/perl or /usr/bin/env perl.

2. Add it to the first line of the file as #!/usr/bin/perl .

3. Give execute permission to the file chmod +x

Features of Perl language:

1. Perl takes the best features from other languages, such as C, awk, sed, sh, and BASIC, among others.

2. Perls database integration interface DBI supports third-party databases including Oracle, Sybase, Postgres, MySQL, and others.

3. Perl works with HTML, XML, and other mark-up languages.

4. Perl supports Unicode.

5. Perl supports both procedural and object-oriented programming.

6. Perl interfaces with external C/C++ libraries through XS or SWIG.

7. Perl is extensible.

8. The Perl interpreter can be embedded into other systems.

To install Perl in Linux:

1. Before proceeding with the installation of Perl in your Linux system, please have a check Perl is installed or not on your Linux system by running the below command:

# perl -v

2. Download the zipped source code available for Unix/Linux by running the below command:

# wget

3. After download the zip file runs the below commands to extract and install Perl:

# tar -xzf perl-5.28.1.tar.gz

# cd perl-5.28.1

# ./Configure -de


# make test

# make install

How to write your Perl script in Linux?

You can write your Perl script in a text file and the text file should have the extension '.pl'. 

To run your Perl script run the below command.

#perl filename

Eg: #perl

Related Posts