My problem: Using getopt::Long , using options with both arguments and no arguments
example1: ./ldapadmin --adduser example2: ./ldapadmin --adduser Manuel,Castillo,F
(basically I want the program to know 'adduser flag is on with no arguments' or 'adduser flag called with arguments')
Both of these should work. Reading the Getopt::Long documentation, I noticed that you can set arguments as optional via : character instead of = (ex. 'adduser:s' => \@adduser) however, in example 1, the value of @adduser is false as if it has never been called!
my possible workaround: use $#ARGV and @ARGV before calling getoptions and keep track of flag this way, if $ARGV[0] contains --adduser and value of $#ARGV is 1, then it mustve been called with no arguments.
problem: Am i using getoptions incorrectly? Module documentation doesn't seem to be too informative, too short if you ask me.
here is a piece of my code---------------------------
my $argn = $#ARGV; # num of args stored in $argn my @argvee = @ARGV; # actual arguments stored in @argvee # above was done before GetOptions loads, since it seems to eat ARGV.. +. GetOptions ( 'adduser:s' => \@adduser, 'deluser=s' => \$deluser, 'addgroup=s' => \@addgroup, 'delgroup=s' => \$delgroup, 'addu2g=s' => \@addu2g, 'delu2g=s' => \@delu2g, 'chsh=s' => \@chsh, 'addalias=s' => \@addalias, 'delalias=s' => \@delalias, 'list' => \$list, 'help' => \$help ); @adduser = split(/,/,join(',',@adduser)); #take in info and split on c +ommas
thanks for your help
In reply to using Getopt::Long, arguments and no arguments possible? by dark314
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |