蔷薇525 发表于 2015-12-27 14:24:44

perl-getopts

  http://search.cpan.org/~nwclark/perl-5.8.5/lib/Getopt/Std.pm



    use Getopt::Std;
getopt('oDI');    # -o, -D & -I take arg.Sets $opt_* as a side effect.
getopt('oDI', \%opts);    # -o, -D & -I take arg.Values in %opts
getopts('oif:');# -o & -i are boolean flags, -f takes an argument
# Sets $opt_* as a side effect.
getopts('oif:', \%opts);# options as above. Values in %opts
  
  在Perl中,可以用getopts()调用来处理命行参数。



1 #!/usr/bin/perl -w
2
3 use Getopt::Std;
4
5 my %opts;
6
7 getopts('v:h',\%opts);
8
9 if ($opts{'v'}) {
10   printf("%s\n", $opts{'v'});       #./xxx -v xxx
11 }
12
13 if ($opts{'h'}) {
14   printf("%s\n", $opts{'h'});       # 1
15 }
  or



1 #!/usr/bin/perl -w
2
3 use Getopt::Std;
4
5 my ($suite, $description);
6
7
8 getopts('CLt:s:b:F:x:VNM');
9
10if(defined($opt_L)) {
11   .......
12}
  
  
  
页: [1]
查看完整版本: perl-getopts