8 (my $head = <<'--end--') =~ s/^\t//gm;
15 my $headlines = 2 + ($head =~ tr/\n/\n/);
16 my $tail = "__END__\n:endofperl\n";
18 @ARGV = ('-') unless @ARGV;
27 my $linenum = $headlines;
29 open( FILE, $_ ) or die "Can't open $_: $!";
31 foreach $line ( @file ) {
33 if ( $line =~ /^:endofperl/) {
34 warn "$_ has already been converted to a batch file!\n";
37 if ( not $linedone and $line =~ /^#!.*perl/ ) {
38 $line .= "#line $linenum\n";
44 $_ .= '.bat' unless /\.bat$/ or /^-$/;
45 open( FILE, ">$_" ) or die "Can't open $_: $!";
47 print FILE "#!perl\n#line " . ($headlines+1) . "\n" unless $linedone;
48 print FILE @file, $tail;
56 pl2bat.bat - a batch file to wrap perl code into a batch file
60 C:\> pl2bat foo.pl bar
61 [..creates foo.bat, bar.bat..]
63 C:\> pl2bat < somefile > another.bat
65 C:\> pl2bat > another.bat
66 print scalar reverse "rekcah lrep rehtona tsuj\n";
68 [..another.bat is now a certified japh application..]
72 This utility converts a perl script into a batch file that can be
73 executed on DOS-like operating systems.
75 Note that the ".pl" suffix will be stripped before adding a
76 ".bat" suffix to the supplied file names.
78 The batch file created makes use of the C<%*> construct to refer
79 to all the command line arguments that were given to the batch file,
80 so you'll need to make sure that works on your variant of the
81 command shell. It is known to work in the cmd.exe shell under
82 WindowsNT. 4DOS/NT users will want to put a C<ParameterChar = *>
83 line in their initialization file, or execute C<setdos /p*> in
84 the shell startup file.
88 C<$0> will contain the full name, including the ".bat" suffix.
89 If you don't like this, see runperl.bat for an alternative way to
92 Perl is invoked with the -S flag, so it will search the PATH to find
93 the script. This may have undesirable effects.
97 perl, perlwin32, runperl.bat