I want a warning message without having to do special coding with
Getopt::Std. 

I'd like for options passed to getops() <note the plural> with the (:)
colon to give a warning message or even possibly die (Haven't
decided that yet) if no argument accompanies them.

But first: The Getopt::Std documentation doesn't say that will happen
but I wondered if it is supposed to or can be made to easily before I
add my own coding.

I can figure out several ways to accomplish my goal but any advice
will be appreciated.

With the script included below; passing a cmdline like 

 ./getoptschk.pl  -a -b -c

Doesn't give any warnings.  
The code passed:  `$optstr ="abc:"'
does indicate there should be an accompanying argument with opt_c

The code is kind of silly but in addition to seeing what would happen
when -c was not given an argument... I was also checking what happened
to any argument on the cmdline.

(This is not a question or complaint)
A secondary suprise was seeing that ARGV is reported as empty at each
stop.  Getopt must slurp all dashed letters at once and shift them off
of ARGV. 

Anyway with this cmdline 

   ./getoptchk.pl -a -b  -c

no warnings occur

Also I noticed passing a completely unexpected dashed argument doesn't
produce a warning either.

  ./getoptchk.pl -a -b  -c -d arg1 arg2

No warnings  
    and I think this should have according to perldoc
Getopt::Std:
[... in part]

       The getopts() function is similar, but you should pass to it
       the list of all switches to be recognized.  If unspecified
       switches are found on the command-line, the user will be warned
       that an unknown option was given.

[...]

But there is more in `perldoc Getopt::Std' that may explain it but
I'll confess I didn't understand that part and I think it only applied
to using "--help" and "--version".. (I've included an abridged
version of that section after the code)

============================================

#!/usr/local/bin/perl

use strict;
use warnings;
use Getopt::Std;

our ($opt_a, $opt_b, $opt_c );
my $optstr ="abc:";
getopts($optstr);

if($opt_a){
   print "Yeah opt_a ARGV is <@ARGV>\n";
}
if($opt_b){
   print "Yeah opt_b ARGV is <@ARGV>\n";
}
if($opt_c){
   print "Yeah opt_c ARGV is <@ARGV>\n";
   ## I think the -c is shifted off already but lets see
   print "Yeah opt_c argument <$opt_c> ARGV is <@ARGV>\n";
}
if(@ARGV){
   print "     All opts complete ARGV is now:
     <@ARGV>\n";
}
====================================================

>From perldoc Getopt::Std
[...]

"--help" and "--version"

[...] snipped first and second paragraph

       Note that due to excessive paranoia, if $Getopt::Std::STAN-
       DARD_HELP_VERSION isn't true (the default is false), then the
       messages are printed on STDERR, and the processing continues
       after the messages are printed.  This being the opposite of the
       standard-conforming behav- iour, it is strongly recommended to
       set $Getopt::Std::STAN- DARD_HELP_VERSION to true.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to