Subject: | OO interface interferes with later functional calls |
Thanks for your earlier response where you suggested using the OO interface to Getopt::Long. However, it appears that doing so breaks later calls to the procedural GetOptions() interface. For example:
package P;
use 5.018;
use Getopt::Long;
my $opt_foo;
sub f {
say "args before OO call: @ARGV";
my $p = new Getopt::Long::Parser;
$p->configure('pass_through');
$p->getoptions(foo => \$opt_foo);
say "args after OO call: @ARGV";
}
package main;
use 5.018;
use Getopt::Long;
P::f;
say "args before procedural call: @ARGV";
our ($opt_bar);
GetOptions('bar');
say "args after procedural call: @ARGV";
Save this as 'test' and run 'perl test --foo --bar'. For me this prints
args before OO call: --foo --bar
args after OO call: --bar
args before procedural call: --bar
args after procedural call:
--bar option given?
So although the procedural GetOptions() call is taking '--bar' off @ARGV, it fails to set the global $opt_bar as would be expected. Somehow this seems to depend on the earlier OO call being in a separate package.