anandvn has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I want to parse a command line option like -DMyMacro=1. Here -D is the option, MyMacro is the string, 1 is the value. In my command line option, there wont be any space between -D and MyMacro=1.
I wrote below program, it works for -D MyMacro=1 but not for -DMyMacro=1

Can any one please suggest/correct my program to acheive my output?

use Getopt::Long;
our %macro = ();
Getopt::Long::Configure ("bundling");
Getopt::Long::Configure ("bundling_override");
GetOptions("I=s"=>\%macro);
print "$_ : $macro{$_}\n" foreach (keys(%macro));
  • Comment on Option Value without space in GETOPT not working?

Replies are listed 'Best First'.
Re: Option Value without space in GETOPT not working?
by ikegami (Patriarch) on May 19, 2010 at 19:54 UTC

    (Placing code in <c>...</c> tags will save you formatting work.)

    Get rid of bundling_override. It specifically overrides the behaviour you want.

      Thanks!!! Now obtained my expected output.