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

In reply to Re: Re: Re: better cli processing by BrowserUk
in thread better cli processing by AlCapone

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.