in reply to Re: Re: better cli processing
in thread better cli processing
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>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Re: better cli processing
by AlCapone (Novice) on Nov 04, 2002 at 00:01 UTC | |
by Aristotle (Chancellor) on Nov 06, 2002 at 11:50 UTC |