yes, sorry, i am using use Getopt::Std; in my code as well. sorry that i
forgot to include that in the code, however it is there in the script.
On Wed, 4 Jul 2001, Pierre Smolarek wrote:
> use Getopt::Std;
>
> ?
>
> ----- Original Message -----
> From: <[EMAIL PROTECTED]>
> To: "Perl Discuss" <[EMAIL PROTECTED]>
> Sent: Wednesday, July 04, 2001 3:54 PM
> Subject: using getopt specifying ARGV values per flag
>
>
> > my script is as follows:
> >
> > #!/usr/bin/perl -w
> >
> > use strict;
> > my $domain;
> > my $path;
> > my %option;
> >
> > getopts("nhfc",\%option);
> >
> > i have 4 options set.
> >
> > typically two will be used together n and f, however i am sure that end
> > users will type in 'script -fn' and 'script -nf'. my concern is that each
> > of these flags takes an argument. i use the value of -n's argument to set
> > the value of $domain and the value of -f's argument to set the value of
> > $path. this works very well when i run the script as:
> >
> > 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();
> > }
> >
> > i cant think of a way to ensure that the correct argument gets attached to
> > the right process, but i'm sure i am not the first person to run up
> > against this :)
> >
> > a perldoc ref will suffice. thanks!
>