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.
I include a space after the #! because some systems interpret the sequence "#! /" as a 4-byte magic number, ignore the line if the space is missing, and thus treat the script as a shell script rather than as a Perl script.
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.
You can invoke a Perl script myscript.pl as follows on any system to run it:
% 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 invocation style that will be used for scripts written 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, and XP), 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: