Tel*_*hus 15
我倾向于使用Getopt :: Long和Pod :: Usage来做到这一点.(在阅读PerlMonks网站上的教程后我养成了这个习惯,所以这里也是这个链接.)它看起来像这个例子:
use Getopt::Long;
use Pod::Usage;
my( $opt_help, $opt_man, $opt_full, $opt_admins, $opt_choose, $opt_createdb, );
GetOptions(
'help!' => \$opt_help,
'man!' => \$opt_man,
'full!' => \$opt_full,
'admin|admins!' => \$opt_admins,
'choose|select|c=s' => \$opt_choose,
'createdb!' => \$opt_createdb,
)
or pod2usage( "Try '$0 --help' for more information." );
pod2usage( -verbose => 1 ) if $opt_help;
pod2usage( -verbose => 2 ) if $opt_man;
Run Code Online (Sandbox Code Playgroud)
在该示例中,除了$opt_man和$opt_help与您无关的选项.我刚刚复制了我在这里的随机脚本的顶部.
之后,您只需要编写POD.这是一个很好的链接,描述了POD本身的基础知识.
编辑:为了回应评论中的OP问题,以下是NAME传递适当选项时如何打印该部分的方法.首先,在选项的哈希中添加另一个选项GetOptions.我们'name' => \$opt_name在这里使用.然后添加:
pod2usage(-verbose => 99, -sections => "NAME") if $opt_name;
Run Code Online (Sandbox Code Playgroud)
详细级别99是神奇的:它允许您选择仅打印的一个或多个部分.请参阅的文件Pod::Usage下-sections的更多细节.请注意,即使您只想要一个部分,-sections(名称)也是复数.
| 归档时间: |
|
| 查看次数: |
12438 次 |
| 最近记录: |