Update2: I just noticed that you aren't printing a newline ("\n" or $/ (by default)) on the end of your print line. Is it possible that the line is getting buffered and not output somehow?
Using this code
#!perl -sw
print $xyz,$/ if $xyz;
__END__
gives
C:\test>210020 -xyz
1
C:\test>210020 -xyz=fred
fred
C:\test>
This is on NT4/AS. NOTE though, the shebang line in my code is advisory only. The actual work being done by the ftype definition which I have set up like this
C:\test>assoc .pl
.pl=perl_script
C:\test>ftype perl_script
perl_script=e:\perl\bin\perl.exe -sw "%1" %*
C:\test>
I haven't used Perl under linux so I'm only guessing here. Have you tried doing
/usr/bin/perl -s yourscript -xyz on your shell command line?
I'm speculating that your shell is not respecting options supplied on the shebang line.
There is more to this as well, once you get this to work in your environment(s), but the rest of this post is irrelevant if you can't get your test script to run.
If you want to use -s in conjunction with strict, you need to take some extra step as the variables set my -s are globals which aren't use strict; complient.
The fix is to this is to use vars qw/$xyz $file/; I'll dig out a short script showing you how I use the -s. Not that I necessarially do it correctly, but it works for me:)
Update: Added a better example of using -s
#!perl -sw
use strict;
use vars qw/$f $s $t $debug/; #! This allows us to reference global va
+rs without violating strict.
=pod comment only!
Note: $::var is (assuming we are in main) shorthand for saying $main:
+:var which is the same as
$var if we aren't using strict and we haven't defined my $var a
+t the current scope.
(I'm sure that I haven't captured the all the semantics in this comme
+nt,
but the Perl lawyers will correct me :)
if -debug not on the command line, it would set my $debug to undef, w
+hich would cause warnings later
when we try to do 'print "something\n" if $debug;'. we could use defi
+ned, but that's hard work.
=cut
my $debug = $::debug || 0;
my $file = $::f || 'd:/temp/temp.dat'; #! Use a tempfile by def
+ault
my $size = $::s || 4096; #! default size
my $time = $::t || time; #! default to now.
print <<OUT;
$0 will run with settings
debug: $debug
file: $file
size: $size
time: $time
OUT
__END__
C:\test>210020
C:\test\210020.pl will run with settings
debug: 0
file: d:/temp/temp.dat
size: 4096
time: 1036283982
C:\test>210020 -debug -f="./temp.dat" -s=8192
C:\test\210020.pl will run with settings
debug: 1
file: ./temp.dat
size: 8192
time: 1036283985
C:\test>
Nah! Your thinking of Simon Templar, originally played by Roger Moore and later by Ian Ogilvy
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.