1

I am trying to parse command line options and values in my script. The script accepts 2 options: updategroup or validategroup. The updategroup option should accept 2 values. For example:

./script.pl -updategroup 'group1' 'enable'

This is how I call GetOptions:

GetOptions(\%args,"updategroup=s{2}","validategroup=s");

After calling it, I would like to store the 2 values in an array. How to fetch this value from the %args hash variable?

toolic
  • 57,801
  • 17
  • 75
  • 117

1 Answers1

5

For the repeat specifier to work, the target must already be an array reference:

use Getopt::Long;    
my %args = ( updategroup => [] );
GetOptions(\%args, "updategroup=s{2}","validategroup=s");
Ben Grimm
  • 4,316
  • 2
  • 15
  • 24