{"id":408,"date":"2012-01-29T17:18:24","date_gmt":"2012-01-29T17:18:24","guid":{"rendered":"http:\/\/www.fbcs.co.uk\/wp\/?p=408"},"modified":"2012-01-29T17:18:24","modified_gmt":"2012-01-29T17:18:24","slug":"408","status":"publish","type":"post","link":"https:\/\/wp.fbcs.co.uk\/408\/","title":{"rendered":"AppConfig and @ARGV"},"content":{"rendered":"

I've been playing with the Perl AppConfig module (http:\/\/search.cpan.org\/~abw\/AppConfig-1.66\/lib\/AppConfig.pm<\/a>)<\/p>\n

It seems that the getopt() method messes up the global @ARGV array even if I pass it a copy.<\/p>\n

For example:
\n\t <\/p>\n


\n

#!\/usr\/bin\/perl
\n\tuse strict;
\n\tuse warnings;
\n\tuse AppConfig;
\n\tmy $opts = AppConfig->new( { CASE   => 0, } );
\n\t$opts->define('config=s', {DEFAULT => ''});
\n\tprint "ARGV: @ARGVn";
\n\tmy $argvCopy = [@ARGV];
\n\tprint "argvCopy: @$argvCopyn";
\n\t$opts->args($argvCopy);
\n\tprint "after args() ARGV: @ARGVn";
\n\t$opts->getopt(qw(auto_abbrev), $argvCopy);
\n\tprint "after getopt() ARGV: @ARGVn"; <\/code><\/p>\n


\n

produces this output<\/p>\n


\n

# appconfig-error.pl --config xyz 123 abc
\n\tARGV: --config xyz 123 abc
\n\targvCopy: --config xyz 123 abc
\n\tafter args() ARGV: --config xyz 123 abc     # @ARGV is still complete
\n\tafter getopt() ARGV: 123 abc                # @ARGV has bits missing <\/code><\/p>\n


\n

This is a problem because I need to call getopt() twice — once to get at the –config option, then I read the configuration file with the file() method, then I re-read the command line options so that they override the ones in the configuration file.<\/p>\n

Using args() is OK — @ARGV is preserved — but I need the extra feature of getopt().<\/p>\n

I've emailed the author, so I'll wait to see what his reply is.<\/p>\n","protected":false},"excerpt":{"rendered":"

I've been playing with the Perl AppConfig module (http:\/\/search.cpan.org\/~abw\/AppConfig-1.66\/lib\/AppConfig.pm) It seems that the getopt() method messes up the global @ARGV array even if I pass it a copy. For example:   #!\/usr\/bin\/perl use strict; use warnings; use AppConfig; my $opts = AppConfig->new( { CASE   => 0, } ); $opts->define('config=s', {DEFAULT => ''}); print "ARGV: @ARGVn"; […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7,46,29],"tags":[],"_links":{"self":[{"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/posts\/408"}],"collection":[{"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/comments?post=408"}],"version-history":[{"count":0,"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/posts\/408\/revisions"}],"wp:attachment":[{"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/media?parent=408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/categories?post=408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wp.fbcs.co.uk\/wp-json\/wp\/v2\/tags?post=408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}