in reply to Re^2: why this not work? -- return value of GetOptions
in thread why this not work?
When I run your code:
use Getopt::Long; my ( $timeout, $show_help ) = 30; unless ( GetOptions("timeout|t=i" => \$timeout, "help|h|?" => \$show_h +elp) && $show_help ) { error_info(); }
I get the following output:
Undefined subroutine &main::error_info called at tmp.pl line 5. </c>This is what I expect. If I call your script with --help like this:
perl -w tmp.pl --help
I get no output. This is also what I expect, because your && expression is not true ($show_help and GetOptions will be true, which never satisfies an unless statement).
Maybe you want to use less clever code like the approach outlined in the documentation of Getopt::Long?
use Getopt::Long; GetOptions( "timeout|t=i" => \my $timeout, "help|h|?" => \my $show_help ) or die "bad options."; $timeout ||= 30; if ( $show_help ) { print "Showing help\n"; error_info(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: why this not work? -- return value of GetOptions
by zapp_prefect (Initiate) on Oct 10, 2016 at 09:08 UTC |