Categories: Ubuntu

How to create and run a Perl script in Ubuntu 22.04 LTS

Perl is a simple and easy-to-learn programming language for beginners. Although Perl is an old-age computing language; however, it can still be used to develop large and complex programs as any structured programming language can do.

The Syntax of Perl is like that of the C programming language. The Per community has contributed more than 250000 software modules that are available on the CPAN (Comprehensive Perl Archive Network). Due to its large community and support, Perl scripts are widely used in Bioinformatics, Multi-tasking, Networking, GUI development, and so on. We have compiled this post to guide you how a Per script can be created and run on Ubuntu 22.04.

Prerequisites
Sponsored

The Perl script can be executed subject to the presence of Perl on Ubuntu 22.04. If you have not installed Perl on Ubuntu 22.04 then you must get the latest version of Perl from the Ubuntu’s official repository by using the following command:

$ sudo apt install perl

How to create and run a Perl script on Ubuntu 22.04

The Perl script can be created and run by using the command line application of Ubuntu 22.04. We have compiled a step-by-step procedure to create and run a Perl script on Ubuntu 22.04.

Step 1: Fire up the Ubuntu terminal (CTRL+ALT+T) and create a “.pl” file as follows:

$ touch test.pl

Step 2: You need to edit the newly created “.pl” file by using any text editor (nano or vim). We have used the nano editor to edit the “test.pl” file via the following command:

$ sudo nano test.pl

Once the file is opened in an editor, write the following line to tell your Ubuntu 22.04 to execute this file (test.pl) using the Perl interpreter:

#!/usr/bin/perl

After that, we added a simple print statement in “test.pl“:

$message=“Hello, Welcome to LinuxHint”;

print($message n);

Sponsored

Once all is done, press “CTRL+S” and “CTRL+X” to save the changes and come out of the editor respectively.

Step 3: Try to run the Perl script “./test.pl” via the following command:

$ ./test.pl

If any execution error occurs (as shown in the above output), you need to provide the execution privileges to the Perl script as follows as we did here with “test.pl“:

$ chmod +x test.pl

Use the following command again to execute the test.pl script.

$ ./test.pl

Here you go!

Conclusion

A Perl script can be created by using any text editor on Ubuntu 22.04. You can run the Perl script from the terminal of Ubuntu 22.04. Perl is an open-source interpreted programming language that is well known in Linux-based operating systems because of its networking and multitasking support. Here, you have learned to create a Perl script and run it on Ubuntu 22.04.

Ubuntu Server Admin

Recent Posts

What our users make with Ubuntu Pro – Episode 2

How Vaultara achieved FedRAMP compliance with Ubuntu Pro Ubuntu Pro helps businesses worldwide to innovate…

17 hours ago

How To Install Zabbix Server 7.4 On Ubuntu 22.04

Zabbix is smart monitoring system on your network. This software written by php mysql. So…

24 hours ago

How To Install Zabbix Server 7.2 On Ubuntu 22.04

Zabbix is smart monitoring system on your network. This software written by php mysql. So…

24 hours ago

SuperTuxKart 1.5 RC2 added GUI option to Choose Vulkan or DirectX 9

SuperTuxKart, the 3D kart racing game, announced the second release candidate for the next 1.5…

24 hours ago

What’s the state of open source adoption in Europe?

New research suggests 86% of European organizations believe open source is valuable for the future…

2 days ago

What are dependencies, and how do you secure them?

Open source software is everywhere. Research shows that around 97% of codebases contain open source…

2 days ago