#!/usr/local/bin/perl # this is pl2bat.p # by djcm Mon 26/2/01 # its intention is to create .bat files that can be run # in DOS or win95 # # example # pl2bat.p ~/bin/website.p > ~/msdos/website.bat # pl2bat.p ~/bin/ebno.p > ~/msdos/ebno.bat # pl2bat.p ~/bin/hello.p > ~/msdos/hello.bat # $shebang = '#!' ; $shebang = "" ; $perl = '\Perl\bin\perl'; $topperl = '#!perl' ; $arglist = '%1 %2 %3 %4 %5 %6 %7 %8 %9' ; eval "\$$1=\$2" while @ARGV && $ARGV[0]=~ /^(\w+)=(.*)/ && shift; # read the shebang $oldshebang = <>; # read the rest @program = <> ; $p = join ( '' , @program ) ; print STDERR "stripping:\n $oldshebang\n"; # this is the top windoze section. it gets executed again by perl and # is interpreted as a big comment $head = '@rem = \'--*-Perl-*-- @echo off '; $head .= $shebang.$perl ; $head .= ' -x -S "%0" ' ; $head .= $arglist."\n" ; $head .= 'goto endofperl @rem \';' ; $head .= "\n" ; # end top $head .= $topperl."\n" ; # OK, now we put the real perl program # then this: $tail = '__END__ :endofperl '; $_ = $head.$p.$tail ; s/\n/\cM\n/g ; # add ctrlM's print $_ ; # @program ;