11 for (".", split ';', $ENV{PATH}) {
13 $0 = "$_/$0" , goto doit if -f "$_/$0";
15 die "`$0' not found.\n";
17 doit: exec "perl", "-x", $0, @ARGV;
18 die "Failed to exec `$0': $!";
23 runperl.bat - an "universal" batch file to run perl scripts
27 C:\> copy runperl.bat foo.bat
29 [..runs the perl script `foo'..]
32 [..runs the perl script `foo'..]
37 This file can be copied to any file name ending in the ".bat" suffix.
38 When executed on a DOS-like operating system, it will invoke the perl
39 script of the same name, but without the ".bat" suffix. It will
40 look for the script in the same directory as itself, and then in
41 the current directory, and then search the directories in your PATH.
43 It relies on the C<exec()> operator, so you will need to make sure
44 that works in your perl.
46 This method of invoking perl scripts has some advantages over
47 batch-file wrappers like C<pl2bat.bat>: it avoids duplication
48 of all the code; it ensures C<$0> contains the same name as the
49 executing file, without any egregious ".bat" suffix; it allows
50 you to separate your perl scripts from the wrapper used to
51 run them; since the wrapper is generic, you can use symbolic
52 links to simply link to C<runperl.bat>, if you are serving your
53 files on a filesystem that supports that.
55 On the other hand, if the batch file is invoked with the ".bat"
56 suffix, it does an extra C<exec()>. This may be a performance
57 issue. You can avoid this by running it without specifying
60 Perl is invoked with the -x flag, so the script must contain
61 a C<#!perl> line. Any flags found on that line will be honored.
65 Perl is invoked with the -S flag, so it will search the PATH to find
66 the script. This may have undesirable effects.
70 perl, perlwin32, pl2bat.bat