as long as
sub first is defined below the BEGIN block,
even if the only argument is '--first'
(i.e. no invalid options),
you'll have
Undefined subroutine &main::first called at .../Getopt/Long.pm line 60
+7.
Available options are:
--first
--help
Invalid options passed to ....pl
BEGIN failed--compilation aborted at ....pl line 17.
which means, as
Corion already mentioned, you have to move the BEGIN block below the subroutines, which defeats the purpose.
besides, from an esthetic viewpoint, it isn't nice, if a program reacts with a "compilation error" to a wrong invocation.
I think I like
haukex's
variant "push @actions" best, and it would even allow for an optional
--ignore-unknown-switches or
--please-dont-die switch to suppress dying on invalid options ;-)
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.