1. 程式人生 > >在 Perl 中使用 Getopt::Long 模組來接收使用者命令列引數 z

在 Perl 中使用 Getopt::Long 模組來接收使用者命令列引數 z

初始化 Perl命令列中所接受的引數,簡化了命令列引數的解析。下面看程式的例子
#!/usr/bin/perl
use strict;
use Getopt::Long;
use Smart::Comments;

my @libs    = ();
my %flags   = ();
my ( $verbose, $all, $more, $diam, $debug, $test, $step);

GetOptions(
        'verbose+'  => \$verbose,
        'more!'     => \$more,
        'debug:i'   => \$debug,
        'lib=s'     => \@libs,
        'flag=s'    => \%flags,
        'test|t'    => \$test,
        'all|everything|universe' => $all,
);


### $verbose
### $more### $debug### $test### @libs;### %flags
這就是使用的方法,下面是詳細解釋,注意看 GetOptions 中的 => 前面的部分。下面是詳解