使用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模块。
本文共 238 字,大约阅读时间需要 1 分钟。
使用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模块。
转载地址:http://jvzjm.baihongyu.com/