Perl Script Characteristics
Perl scripts are just text files, so you can create them using any text editor. All Perl scripts in this chapter follow the Unix convention that they begin with a #! (shebang) line that specifies the pathname of the program to use for executing the script. The line I use is as follows:
#! /usr/bin/perl -w
On Unix, you'll need to modify the #! line if the pathname to Perl is different on your system, such as /usr/local/bin/perl5 or /opt/bin/perl. Otherwise, Perl scripts won't run properly on your system.
The -w option tells Perl to issue a warning if it finds that you use questionable language constructs or perform operations such as printing uninitialized variables. This is useful because it can alert you to code that should be rewritten.
% perl -w myscript.pl
However, you may also be able to execute the script without naming the perl program explicitly. On Unix, do this by changing the file mode with chmod to make the script executable:
% chmod +x myscript.pl
Then you can run the script just by typing its name:
That is the script invocation style that will be used for examples shown in this chapter. The leading "./" should be used if the script is located in your current directory (".") and your shell does not have the current directory in its search path. Otherwise, you can omit the "./" from the command name:
Under Windows NT-based systems (NT, 2000, XP, 2003), you can set up a filename association between Perl and filenames ending in .pl. For example, if you install ActiveState Perl, its installation program allows you to set up an association so that filenames ending with .pl are run by Perl. In that case, you can run Perl scripts just by naming them on the command line: