Running Perl

Perl programs are usually just perl scripts. Perl scripts are sequences of perl commands stored in a plain ascii text file. Scripts are executed by passing them to the perl interpreter program installed on your system.

Assuming perl is installed on your system, the simplest way to run a perl script is by invoking the perl interpreter on the command-line followed by the name of the perl script.

>perl MyScriptFile


(Here we are taking the '>' character to mean a command-line prompt)




Naming perl script files


It's common practice to name your perl scriptfiles with a .pl suffix as in:

MyScriptFile.pl

On computers running Windows, this allows such files to be associated with the perl interpreter program. This way, you can execute a perl script on a Windows computer by just clicking on it.



Command-line options

Flags can be specified on the command-line which the way the perl script is executed.

A commonly used flag is -w which causes warnings of potential problems with your script to be generated and displayed.

>perl -w MyScriptFile.pl



Simpler execution under UNIX

If your computer is running UNIX and supports the shebang "#!" syntax for invoking a script interpreter, you can make your script files directly executable by making the first of the line script like so:

#!/usr/bin/perl

Or if you want to add the warning command-line option:

#!/usr/bin/perl -w

Then turn on the the execute bit for the script file with a UNIX command such as:

>chmod +x MyScriptFile

Now to run the script file, just enter its name on the command-line

>MyScriptFile

The above assumes that '/usr/bin/perl' is the directory path to the perl interpreter on your system. You should be able to discover it's true location with the command:

>which perl