in reply to Passing switches through pl2bat scripts

Just spitballing a posibility

perl -x
This enables the feature that allows perl to read stdin until it sees the '#! perl' and then start reading the input until __END__. As an argument to the perl interpreter itself, it's never seen as part of the @ARGV array of the script, so 'getopt' will never see it

Your next -x however, is being passed to the script as an argument to the script itself, so 'getopt' can see it.

Replies are listed 'Best First'.
Re^2: Passing switches through pl2bat scripts
by PhilHibbs (Hermit) on Nov 17, 2003 at 14:53 UTC
    The first -x is a red herring, and perhaps I should have chosen a better example and avoided using -x in my script. However, as the results of join(' ',@ARGV)."\n"; demonstrate, the perl script ends up with a -x that is not processed by getopt(). Here's a better example:
    @rem = '--*-Perl-*-- @echo off perl -x -S "%~dpnx0" -z %* goto endofperl @rem '; #!perl use Getopt::Std; print join(' ',@ARGV)."\n"; my %opts = (); getopt('z', \%opts); print "z found\n" if $opts{'z'}; __END__ Results: C:\>x -z C:\>x -z -z -z z found :endofperl
      The issue is basically the same. At some point 'perl' stops accepting arguments/options to the interpreter itself and starts handing them to the script as @ARGV.

      In a typical invocation

      perl @perlOpts filename.pl @scriptOpts

      everything after filename.pl shows up in @ARGV.

      The question becomes, where is that point in your invocation of 'perl' in this particular context?

        In my example, the "%~dpnx0" is the equivalent of filename.pl in your example, so the -z should be passed through. My question has been answered, though, I was misled by the documentation of getopt() and am now using getopts() instead.