These classnotes are depreciated. As of 2005, I no longer teach the classes. Notes will remain online for legacy purposes

UNIX01/Starting A Perl Script

Classnotes | UNIX01 | RecentChanges | Preferences

Perl is just an interpretor, much like the BASH shell or a BASIC interpretor. Thus, it must be called before a Perl script can be ran.

We learned last week that every script under UNIX needs to start with a line telling UNIX where to find it's interpretor. With Perl, this is no different.

You begin a Perl script with some line that calls Perl on your system:

 #!/usr/bin/perl

(Note here that you may have to modify this path depending upon where Perl is installed).

Sometimes you can specify a specific class of Perl interpretors by version (for example, Perl version 5.0 is very different from Perl version 6.0) thusly

 #!/usr/bin/perl5

Perl has a number of command-line options that are very useful when writing a Perl script. Some have specific uses in CGI web-design, others are applicable everywhere.

The "-w" option tells Perl to run with warnings.

 #!/usr/bin/perl -w

This warns you of syntax and other problems with your code. If your Perl script is running in some sort of automated environment (such as a cron job or from a web-site) then you may want this information repressed. You can do this with the "-X" option:

 #!/usr/bin/perl -X

If you are running your Perl script as a CGI program from a web-site, then you have a very serious security concern in the form of "data tainting". Data tainting (which we will examine in great detail in UNIX03), in a nutshell, is when a piece of control code makes its way into a script or application. For an interpretive and embeddable language like Perl, data tainting can be very serious. It is possible in an unchecked Perl script to pass commands that could be interpreted by a shell or even Perl that could compromise a system. To battle against this problem, you can pass the "-t" (for warnings) or "-T" (for more serious checks) options

 #!/usr/bin/perl -T

You can also mix and match command line options,

 #!/usr/bin/perl -wT


Classnotes | UNIX01 | RecentChanges | Preferences
This page is read-only | View other revisions
Last edited July 26, 2003 2:34 am (diff)
Search:
(C) Copyright 2003 Samuel Hart
Creative Commons License
This work is licensed under a Creative Commons License.