Running a perl program is relatively simple. Once you have a program written out, all you have to do is to invoke the perl interpreter along with the filename.
perl filename.pl
If you are running on a unix system. You can make the file executable using the chmod +rx function call. In order to do this you must then have the following line be the first line in your perl program.
#! /usr/local/bin/perl
Where "/usr/local/bin/perl" is the path of your perl interpreter. In order to find this path on unix just type:
which perl
on the command line.
Let's practice writing a small program at our console. Using any editor type the following code:
#! /usr/local/bin/perl
print "Hello World!\n";
Now save your program with a .pl extension. Let's call it hello.pl. From the command line then type:
perl hello.pl
You should then see the following output:
Hello World!
You have just written your first perl program.
![]() |
![]() |