in reply to Re: GetOpt Organization
in thread GetOpt Organization

tsk, tsk.. no monk checks for the return status of GetOptions ?? You want your program running with invalid option passed?

Here is my usual pattern:
use Getopt::Long; use Pod::Usage; unless ( GetOptions ( "color=s"=>\$par_color, "help" => \$par_help, ) ) {pod2usage(-verbose => 1,-exitval => 'NOEXIT'); &wait_for_in +put; exit;} if (defined $par_help){pod2usage(-verbose => 1,-exitval => 'NOEXIT'); +&wait_for_input; exit;}
The function pod2usage supports -exitval => 'NOEXIT' (ie normally it exits the program unless you specify it to not do) useful if you started the program without a console, like in a Tk application as Tk Tartaglia's triangle fun - Pascal's triangle fun.

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: GetOpt Organization (error check)
by Anonymous Monk on Mar 10, 2015 at 11:29 UTC

    tsk, tsk.. no monk checks for the return status of GetOptions ?? You want your program running with invalid option passed?

    The validation options and return value of GetOptions , and esp their combination, isn't that useful

    You still have to do your own validation, so let GetOptions warn, then write your program

      Yes you are absolutely right.

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re^3: GetOpt Organization (error check)
by karlgoethebier (Abbot) on Mar 10, 2015 at 10:29 UTC
    ...You want your program running with invalid option passed?

    No, perish the thought.

    When i run the snippet i posted with an invalid option i get:

    monks>options.pl --goo Unknown option: goo

    Best regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      Well, i have to dissent my friend, try to add print "Here i'm still alive!\n";
      at the bottom of your snippet: i get
      Unknown option: goo Here i'm still alive!


      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        Mmh, so did i. I still get Unknown option: goo but no survivor.

        «The Crux of the Biscuit is the Apostrophe»