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:
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:
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:
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:
After that, we added a simple print statement in “test.pl“:
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:
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“:
Use the following command again to execute the test.pl script.
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.