perl处理命令行参数

使用Getopt::std模块

代码如下

use strict ;
use Getopt::Std ;
sub test{
use vars qw($opt_d $opt_f) ;
getopts('d:f:') ;
print $opt_d, "\n" ;
print $opt_f, "\n" ;
}
&test() ;
1 ;

'd:f:' d和f后面有冒号,表示-d和-f后面必须跟参数。

对于更复杂的命令行参数处理,请看Getopt::long模块。