This is yet another reason why I like the "store options in a hash" ability:
When used, this shows:#!/usr/bin/perl use strict; use warnings; use Getopt::Long; my %args; GetOptions(\%args, 'adduser:s@'); use Data::Dumper; print Dumper(\%args);
So, if the option isn't specified, it doesn't end up as a key in the hash. If the option is specified, but without any parameter, the key shows up, but the value is an array reference containing an empty string. If the option is specified with a parameter, then the key is there, pointing to an array containing the parameter. Note that --adduser and --adduser "" both do the same thing. Which is probably fine.$ perl ./a.pl $VAR1 = {}; $ perl ./a.pl --adduser $VAR1 = { 'adduser' => [ '' ] }; $ perl ./a.pl --adduser blah $VAR1 = { 'adduser' => [ 'blah' ] };
In reply to Re: using Getopt::Long, arguments and no arguments possible?
by Tanktalus
in thread using Getopt::Long, arguments and no arguments possible?
by dark314
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |