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 example.pl.
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 https://www.cpan.org/src/5.0/perl-5.28.1.tar.gz
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.
Eg: #perl hello.pl