D
dcruncher4
my perl script takes two arguments -s and -t and both require a value.
this is the code
#! /bin/perl -w
use strict;
use Getopt::Std;
use constant OPTS => "s:t:" ;
use vars qw (%opt) ;
getopts(OPTS,\%opt) or &usage();
if (defined($opt{s})) {
print "you supplied $opt{s} as value for -s\n" ;
}
if (defined($opt{t})) {
print "you supplied $opt{t} as value for -t\n" ;
}
sub usage() {
print "your usage is incorrect\n" ;
exit(-1);
}
if i call the script as follows
script_name -s first_argument -t second_argument
you supplied first_argument as value for -s
you supplied second_argument as value for -t
which is fine.
Now if I call it as
script_name -s -t second_argument
the output is
you supplied -t as value for -s
Shouldn't getopts go to subroutine usage or spew out an error message
that
-s is a mandatory parameter.
What am I missing?
this is the code
#! /bin/perl -w
use strict;
use Getopt::Std;
use constant OPTS => "s:t:" ;
use vars qw (%opt) ;
getopts(OPTS,\%opt) or &usage();
if (defined($opt{s})) {
print "you supplied $opt{s} as value for -s\n" ;
}
if (defined($opt{t})) {
print "you supplied $opt{t} as value for -t\n" ;
}
sub usage() {
print "your usage is incorrect\n" ;
exit(-1);
}
if i call the script as follows
script_name -s first_argument -t second_argument
you supplied first_argument as value for -s
you supplied second_argument as value for -t
which is fine.
Now if I call it as
script_name -s -t second_argument
the output is
you supplied -t as value for -s
Shouldn't getopts go to subroutine usage or spew out an error message
that
-s is a mandatory parameter.
What am I missing?