I'm using Perl's GetOpt::ArgParse module to handle runtime-argument parsing. However, I'm having problems accessing the argument values of the parser object after they are parsed.
require Getopt::ArgParse; $ap = Getopt::ArgParse->new_parser { prog => "test_argparse.pl", description => "Test the Getopt::Argparse module" } $ap->add_argument('-c', '--count', type => Scalar); $ap->add_argument('-f', '--flag', type => Bool); $args = $ap->parse_args(); # Now, I am assuming that $args is a pointer to a hash array # that contains elements for "count" and "flag" if (! defined($args{'count'})) { print "count not defined\n"; } # The above code always prints the message even though I # executed the program with both options: # # > test_argparse.pl -c 10 # > test_argparse.pl --count 10
So how do I access the arguments in $args? I'm coming from a Python background and while Python makes the arguments attributes of the arg object, Perl seems to store it in a dictionary I looked at this website for helpe (http://search.cpan.org/~mytram/Getopt-ArgParse-1.0.2/lib/Getopt/ArgParse.pm) but there were no examples. I tried the "say" example but it didnt' work.
In reply to How to access GetOpt::ArgParse arguments? by SQADude
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |