The -s switch is a little problematic on Win32, at least with AS 5.6. perl -s script -VAR=1 works fine but without the -s on the command line (ie with #!perl -s) it does not work. In other words it seems to me that while -w is read off the shebang on Win32 -s is not. Anyway -s implements a very simple mechanism. I would suggest using one of the Getopt modules is a better way to go but you can fake its behaviour with a handful of lines:

C:\>type test.pl #!/usr/bin/perl use strict; our ( $HELLO, $WORLD ); # fake the behaviour of -s { no strict; my @other = (); while(my $term = shift @ARGV) { $term =~ s/^\-/\$/ ? eval $term : push @other, $term; } @ARGV = @other; } print "Got $HELLO $WORLD\n"; print "\@ARGV = ( @ARGV )\n"; C:\>perl test.pl -HELLO=hello -WORLD=world other arguments Got hello world @ARGV = ( other arguments )

Note that this code does a trusting string eval which is dangerous but on Win32 your security is already shot ;-). You should probably make it more secure by validating the $term string before the eval but as whoever executes it already has a shell in which to execute arbitrary commands (and the script will exec with their perms) I don't really see it as a major security issue.

cheers

tachyon


In reply to Re: perl2exe with -s by tachyon
in thread perl2exe with -s by Scarborough

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.