The environment necessary to program and run Perl scripts is provided on all ITS UNIX hosts. While ITS supports the use of the perl command, ITS does not support programming syntax or program debugging in any way.
Setting up Perl on UNIX
It is relatively simple to get started with Perl. Perl does not require a compiler or any special tools. All it requires is the perl executable found in /usr/usc/perl/default/bin.
To make sure perl is in your path and set up the manpages for it, type source /usr/usc/perl/default/setup.csh. You can add this to a new line at the end of your ~/.login file in order to avoid typing it every time.
There are two ways of using Perl, interactive mode, and scripted mode. To start perl in interactive mode, just type perl. This mode requires that you type the script line by line into the perl program. When you are finished, hit Control-D to execute the program. This is not generally recommended for any program of non-trivial length because it is hard to save your program in this mode. Scripting mode involves creating a script in a text editor, then using perl to execute that script. This is a much better mode for repetitive use and debugging.
Creating a Script
An example script is given at the bottom of this page to get you started. All Perl scripts should begin with a #! statement. #! tells the UNIX OS what program to use to run the perl script and optionally what arguments to use for it. A good statement would be #!/usr/usc/perl/default/bin/perl. If you named your script file perlScript.pl, you could run it by typing perl perlScript.pl.
Alternatively, if you want the script to appear to be a stand-alone program, you must make sure two conditions are met. First, it must have a valid #! statement on its first line, as described above. The second condition is that the perl script must be executable on the UNIX system. You can accomplish this by typing chmod 700 perlScript.pl. Please refer to man chmod or our UNIX documentation more information on UNIX permissions. Once the script file meets those two conditions, you can execute it simply by typing the filename, such as perlScript.pl.
Here is a simple example script to get you started with the perl interpreter program. You can copy it into a text editor, or you can download it here .
# filename: perlScript.pl
# This is a sample perl script.
# It prints a simple phrase
print "This is a Perl program.\n\n";
# End of Script
Getting HelpFor help in compiling and running Perl programs, please refer to the perl manpage by typing man perl. Help in using the Perl programming language can be found online at either http://www.perl.org/.
The ITS Customer Support Center can be reached at 213-740-5555 or email@example.com for help launching perl, or to report problems with the installed perl package. ITS does not help support programming syntax or debugging. If you are learning Perl for a class, please consult your TA or professor for help with the Perl language.
February 04, 2011