If the Perl script is a standalone program, rather than a module which will be used by other Perl scripts, then you will probably end up copying (installing) the file in a bin directory, likely your own ${HOME}/bin directory. At that point, you don't want to have to type perl $HOME/bin/script.pl
; you want to type just script
. So, you probably 'compile' the Perl script by copying it to the file with the basename of the script.
In terms of make
, you have to educate it on how to convert script.pl
to script
. In the simplest case, all that takes is:
CP = cp
MX = chmod +x
.SUFFIXES: .pl
.pl:
${CP} $< $@
${MX} $@
SCRIPT = script
all: ${SCRIPT}
The result can be installed by another copy, or a move. As long as the script starts with a shebang that identifies a working Perl interpreter (so #!/bin/perl
or #!/usr/bin/perl
), then you don't have to worry any more. One trick to get the script to use the Perl found on your PATH is:
#!/usr/bin/env perl
The env
command sets environment variables (not used here) and executes the program named afterwards (with arguments, in the general case; in a shebang line, you are limited to one argument, which is 'perl' here). Using this saves you having to edit your scripts.
Note that this does not ensure that prerequisite modules are installed, whereas the Build module does do that. For details, see the answer describing Build. However, if your script only uses standard (Core) modules, you don't have to fret about that. Since you can't pass the '-w' option via the shebang any more, it is normally a very good idea to include the following lines at the top of your script:
use strict;
use warnings;
If you need to set the correct Perl in the shebang, then you need a program to fix the interpreter. The first edition of the Camel book included a script, fixin
, which can do that job.