[Perl]实用性很强的模块Getopt::Std和Getopt::Long
时间:2005-10-08 来源:huhuegg
这两个模块能够很容易处理命令开关,以后就不用自己在程序中分析处理了。
这两个模块无需到CPAN下载,perl自带。
#!/usr/bin/perl -w
use Getopt::Std;
Getopt::Std::getopts('a:b:c:de', \%options);
print "-a:$options{a} ";
print "-b:$options{b} ";
print "-c:$options{c} ";
print "-d:$options{d} ";
print "-e:$options{e} ";
#!/usr/bin/perl
use Getopt::Long;
Getopt::Long::GetOptions(
'page=i' => $page,
'onoff!' => $onoff,
'help' => $wants_help,
'name=s' => $name,
'number:i' => $number);
if(defined($page)){
print "page flag set to $page ";
}
if(defined($onoff)){
print "onoff flag set to $onoff ";
}
if(defined($wants_help)){
print "help flag set to $wants_help ";
}
if(defined($name)){
print "name flag set to $name ";
}
if(defined($number)){
print "number flag set to $number ";
}