my $man = 0;
my $help = 0;
## Parse options and print usage if there is a syntax error,
## or if usage was explicitly requested.
GetOptions('help|?' => \$help, man => \$man) or pod2usage(2);
pod2usage(1) if $help;
pod2usage(-verbose => 2) if $man;
#-----------------------------------------------------------------
#---------------- Documentation/Usage/Help ------------------
=head1 NAME
sample - Using GetOpt::Long and Pod::Usage
=head1 SYNOPSIS
sample [options] [file ...]
Options:
-help brief help message
-man full documentation
=head1 OPTIONS
=over 8
=item B<-help>
Print a brief help message and exits.
=item B<-man>
Prints the manual page and exits.
=back
=head1 DESCRIPTION
B<This program> will read the given input file(s) and do something
useful with the contents thereof.
=cut
差不多複製/從網上粘貼的例子。但是,當我做script.pl --help
沒有打印,腳本退出。
如果您切換回使用合法的POD,該怎麼辦? – ikegami
我很抱歉,我對perl顯然很陌生 - 你是什麼意思的合法POD? – MrDuk
你知道你說過的部分「幾乎從在線示例複製/粘貼」?那麼,你所做的每一個改變似乎都是一個錯誤。 – ikegami