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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.