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

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);

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

Advantech AOM-2721 is now Ubuntu Certified

Canonical announces that the Advantech AOM-2721 is officially joining the list of Ubuntu Certified Hardware.…

8 hours ago

Ruby and Rails Performance Roundup: The Backlog Edition

Yet again instead of tweets, a blog post. The backlog got out of hand -…

8 hours ago

How to Deploy OpenProject on Ubuntu VPS

This article provides a guide demonstrating how to deploy OpenProject on Ubuntu VPS. What is…

9 hours ago

Canonical integrates NVIDIA Nemotron 3.5 Lightning with Ubuntu for always-on AI agents

Canonical is pleased to announce that  NVIDIA’s newly introduced NVIDIA Nemotron 3.5 Lightning, an open,…

2 days ago

Xfwl4’s Second Preview Release

I’m pleased to announce the second preview release of xfwl4, Xfce’s Wayland compositor, version 4.21.1.…

2 days ago

How to Install, Secure, and Set Up MySQL on Ubuntu 26.04 LTS

If you have been using an ecommerce store to place online orders or have been…

3 days ago