<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>
<DIV>Windows version of Perl come with a script called pl2bat, which converts a
perl script to a batch file. This is done by wrapping the perl script with
some line of batch code. An example for a single line ‘Hello world’ script
is later in the email. The batch file initially runs as a batch file, then
calls the Perl interpreter using the same batch file as the input perl
script. The command to do that is: “perl –x –S %0”. </DIV>
<DIV>This looks for the Perl interpreter using the PATH environment
variable. </DIV>
<DIV> </DIV>
<DIV>You could change the wrapper batch file to look for Perl in multiple
places.</DIV>
<DIV> </DIV>
<DIV>Windows does not use the #! line to locate perl, except in the special case
of running the script under Apache as a CGI script.</DIV>
<DIV> </DIV>
<DIV>Instead of pulling in the modules with ‘use’ statements, you can wrap the
use statements with an eval expression. Something like this (untested)
code:</DIV>
<DIV>eval (“use Foo:: Bar;”);</DIV>
<DIV>if ($@) {</DIV>
<DIV> print error message and exit.</DIV>
<DIV>}<BR></DIV>
<DIV> </DIV>
<DIV>===== EXAMPLE BATCH FILE WRAPPED PERL SCRIPT ==============</DIV>
<DIV>@rem = '--*-Perl-*--<BR>@echo off<BR>if "%OS%" == "Windows_NT" goto
WinNT<BR>perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9<BR>goto
endofperl<BR>:WinNT<BR>perl -x -S %0 %*<BR>if NOT "%COMSPEC%" ==
"%SystemRoot%\system32\cmd.exe" goto endofperl<BR>if %errorlevel% == 9009 echo
You do not have Perl in your PATH.<BR>if errorlevel 1 goto
script_failed_so_exit_with_non_zero_val 2>nul<BR>goto endofperl<BR>@rem
';<BR>#!perl<BR>#line 15<BR>print "hello world\n";</DIV>
<DIV> </DIV>
<DIV>__END__<BR>:endofperl<BR></DIV></DIV>
<DIV> </DIV>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">Indy
Singh<BR>IndigoSTAR Software -- www.indigostar.com</DIV>
<DIV
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<DIV style="FONT: 10pt tahoma">
<DIV> </DIV>
<DIV style="BACKGROUND: #f5f5f5">
<DIV style="font-color: black"><B>From:</B> <A title=jztam@yahoo.com
href="mailto:jztam@yahoo.com">J Z Tam</A> </DIV>
<DIV><B>Sent:</B> Friday, June 24, 2011 2:32 PM</DIV>
<DIV><B>To:</B> <A title=tpm@to.pm.org href="mailto:tpm@to.pm.org">Toronto Perl
Mongers</A> ; <A title=mike@stok.ca href="mailto:mike@stok.ca">Mike Stok</A>
</DIV>
<DIV><B>Subject:</B> [tpm] Is there a way to choose from several
interpreters,using the hashBang?</DIV></DIV></DIV>
<DIV> </DIV></DIV>
<DIV
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<TABLE style="COLOR: #000000" border=0 cellSpacing=0 cellPadding=0>
<TBODY>
<TR>
<TD vAlign=top>CAVEAT: Windoze XP and Server2003/5 here.
Ugh. I'm trying to figure out an elegant way to have multiple
install trees able to be sourced, either just before a perl program is
executed, or at the time the hashBang line is encountered. <BR><BR>I
thought there was a nifty cool way to select the particular
perl interpreter just before the #! line, or actually AT the
#! line.<BR>1. Q: what if the caller's %PATH% environment variable
does NOT contain a valid pathToInterpreter<BR>2. Q: What if the the
install tree that is eventually found, is missing a use'd or
require'd package, or the wrong version of the
package?<BR><BR></TD></TR></TBODY></TABLE>
<P>
<HR>
_______________________________________________<BR>toronto-pm mailing
list<BR>toronto-pm@pm.org<BR>http://mail.pm.org/mailman/listinfo/toronto-pm<BR></DIV></DIV></DIV></BODY></HTML>