Has anyone used Getopt::Auto? I'm keen to get it going but haven't been able to get my test code (taken from the man page) to run the way I think it should.

From the man page:

"Getopt::Auto" is happy for you to use "long" ("--gnu-style"), "short" ("-oldstyle") or even "bare" command names, ("myprogram edit foo.txt", CVS-style) on the condition that you are consistent. Additionally, if you use bare or long style commands, then any short options passed before a command name will be sent into %main::options. For instance, given use Getopt::Auto ( "edit" => "open a file for editing", "export" => "write out the data as an ASCII file" ); "yourprog -vt edit -x foo.txt" will perform the following: $main::options{v} = 1 $main::options{t} = 1 edit("-x", "foo.txt");

My code:

#!/usr/bin/perl use strict; use warnings; # Test bed for Getopt::Auto use Getopt::Auto ( [ "edit" => "open a file for editing", "export" => "write out the data as an ASCII file" ] ); our %options; { print "Dump arguments!!\n"; foreach ( keys %main::options ) { print "$_ : $main::options{$_}\n"; } }

The result:

[alex@foo dev]$ perl -w go.pl -vt edit -x foo.txt Dump arguments!! Use of uninitialized value in subroutine entry at /usr/lib/perl5/site_ +perl/5.8.0/Getopt/Auto.pm line 140. Can't use string ("") as a subroutine ref while "strict refs" in use a +t /usr/lib/perl5/site_perl/5.8.0/Getopt/Auto.pm line 140. END failed--call queue aborted.

--t. alex
Life is short: get busy!

In reply to Getopt::Auto question by talexb

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.