How to run Perl script in Linux?
Here you will find out:
- how to check whether you have Perl installed
- how to create a new text file
- how to run a Perl script
- when DiskInternals can help you
Are you ready? Let's read!
Learning Perl programming in Linux
If you’re interested in learning Perl programming, this article details the core information you need to get started. Normally, when a programmer is learning a new language, their first script will be the “Hello World” script. Thus, in Perl programming, you will need to learn how to print “Hello World,” first, before attempting other, more intricate scripts.
Check whether you have Perl installed
Before you can run Perl, it must be installed on your Linux system. You can check for Perl on your Linux system with this command in the terminal:
Perl –v
If Perl is already installed on your system, the above code will print the current version of Perl you have on the system. But, if Perl is not on your system, you’ll get an error response.
Visit the official Perl website to download and install Perl on Linux.
How to create a new text file
Perl scripts are saved with the extension .pl; although adding the extension to your script’s name is unnecessary, you should just know about it. You can write your Perl scripts in a text editor such as Notepad, Vi, TextEdit, Emacs, Ultra Edit, Textmate, etc. However, you should never write a Perl program using document editors such as MS Word, OneNote, OpenOffice Writer, etc.
To start writing your first Perl program, launch your text editor and type the following commands:
Save the Linux Perl script with any name of your choice. For example, you can save the file as “test.pl”.
How to run a Perl script
Now that you have written your first Perl script, the next step is to run the script. This will take you back to the terminal.
- Open a terminal and change the directory to where your Perl script is saved
- For DOS systems, type cd c:\perl\scripts
Then run:
This script will ask you to enter your name, and when you do so, hit the “Enter” key. Perl will call your name with this response.
Do you want to get files from Linux in Windows?
Let’s say you are working with a Windows PC and need to get some important files from your Linux partitions; how would you do that? Well, Windows won’t allow you to access Linux partitions, but with DiskInternals Linux Reader, you can easily access and get any file saved from your Linux partition. DiskInternals Linux Reader supports all Linux file systems and can read any Linux partition.
Also, DiskInternals Linux Reader features a user-friendly interface and displays all your Linux partitions just as Windows displays all your drives in its File Explorer page. DiskInternals Linux Reader software is available for free, and it works for both virtual machines and dual-boot setups.