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();
}
|