http://qs1969.pair.com?node_id=594626


in reply to The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!

I dont't understand the comment:
# Check this last to avoid parsing options as Places, # and so don't override $opt_man verbose level my @places = @ARGV; pod2usage(-verbose => 1) && exit unless @places;
I evaluate "--help" and "--man" as "subs", like
GetOptions( "help|?" => sub { pod2usage( -verbose => 1, -exitval => 0 ); }, "man" => sub { pod2usage( -verbose => 2, -exitval => 0 ); }, # ... ) or pod2usage( -verbose => 1, -exitval => 1);

The '-exitval' lets pod2usage exit the programm for you.

The line "or pod2usage( -verbose => 1, -exitval => 1);" is now added to my code; until I read your article I never thought of checking GetOptions(). But it is a good idea! :)

Replies are listed 'Best First'.
Re^2: The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!
by hippo (Bishop) on Aug 31, 2023 at 10:59 UTC
    The '-exitval' lets pod2usage exit the programm for you.

    Better yet, even without passing -exitval pod2usage will exit for you as it does this by default. If for some reason you do not want pod2usage to exit you need to pass in the 'NOEXIT' string value:

    pod2usage (-verbose => 1, -exitval => 'NOEXIT'); print "This line will print only because we used 'NOEXIT'.\n"; pod2usage (-verbose => 1); print "This line will never be reached.\n";

    🦛