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!

Reply via email to