On Wed, Jul 04, 2001 at 09:54:17AM -0500, [EMAIL PROTECTED] wrote:
[snip]
> script -nf domain.com client
> 
> but when i try mixing the two up, or trying something like:
> 
> script -f client -n domain.com
> 
> i still get the incorrect output. i am sure this is because i am setting
> the values based on their order within @ARGV:
> 
> #if -n, then set $domain equal to the argument
> if ($option{n}) {
>   $domain = $ARGV[0];
>   shift @ARGV;
>   add();
> }
> 
> #if -f, then set $path
> if ($option{f}) {
>   $path = "/etc/nameserver/$ARGV[0]";
>   shift @ARGV;
>   update();
> }
[snip]


You're using a Getopt::* module to parse your command-line, then proceeding
to parse it yourself.  This is a bad idea, and it's what's getting you in
trouble.  You should be using an option spec where 'f' and 'n' take
arguments, i.e. "f:n:".

If you're absolutely stuck on both:

    -fn client domain.com

AND

    -f client -n domain.com

working then there isn't much Getopt::Std can do to help you.  You'll have
to look for another command-line parser that'll do the job.

There are various incantations of Getopt::Long you may be able to use to get
what you want.  Using a callback routine is one possibility, looping through
with 'require_order' set until there are no more options is another.

Getopt::Std and Getopt::Long, and their C counterparts, allow for no
whitespace between the switch and its argument.  In the face of options that
take arguments, it's difficult for a parser to determine if:

    -fn client domain.com

means:

    -f with an argument of "n", and two trailing arguments

OR

    -f with an argument of "client", -n with an argument of "domain.com"


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

Reply via email to