Improve dual-universe comments in hints/sunos_4_1.sh
[p5sagit/p5-mst-13.2.git] / win32 / bin / runperl.bat
1 @rem = '--*-Perl-*--
2 @echo off
3 perl -x -S %0 %*
4 goto endofperl
5 @rem ';
6 #!perl -w
7 #line 8
8 $0 =~ s|\.bat||i;
9 unless (-f $0) {
10     $0 =~ s|.*[/\\]||;
11     for (".", split ';', $ENV{PATH}) {
12         $_ = "." if $_ eq "";
13         $0 = "$_/$0" , goto doit if -f "$_/$0";
14     }
15     die "`$0' not found.\n";
16 }
17 doit: exec "perl", "-x", $0, @ARGV;
18 die "Failed to exec `$0': $!";
19 __END__
20
21 =head1 NAME
22
23 runperl.bat - an "universal" batch file to run perl scripts
24
25 =head1 SYNOPSIS
26
27         C:\> copy runperl.bat foo.bat
28         C:\> foo
29         [..runs the perl script `foo'..]
30         
31         C:\> foo.bat
32         [..runs the perl script `foo'..]
33         
34
35 =head1 DESCRIPTION
36
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.
42
43 It relies on the C<exec()> operator, so you will need to make sure
44 that works in your perl.
45
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.
54
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
58 the ".bat" suffix.
59
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.
62
63 =head1 BUGS
64
65 Perl is invoked with the -S flag, so it will search the PATH to find
66 the script.  This may have undesirable effects.
67
68 =head1 SEE ALSO
69
70 perl, perlwin32, pl2bat.bat
71
72 =cut
73
74 __END__
75 :endofperl
76