1.使用perl自带的Long.pm模块,
use Getopt::Long;
Getopt::Long::GetOptions(
'c=s' => \$community, //c是传递的参数标识符,s代表传递的参数是字符串,参数将传递给$community这个变量
'H=s' => \$host_name,
'v=i' => \$version, //i代表传递的参数是数字
);
2.使用perl自带的Std.pm模块
use Getopt::Std;
use vars qw($opt_H $opt_c $opt_v);
getopts('H:c:v:');
$host_name = $opt_H if $opt_H;
$community = $opt_c if $opt_c;
$version = $opt_v if $opt_v;
3.自己写的脚本
while (defined($arg = shift)){
if ($arg eq "-H"){
$host_name = shift;
}elsif ($arg eq "-C"){
$community = shift;
}elsif ($arg eq "-v"){
$version = shift;
}elsif ($arg eq "-h"){
&print_help;
}else {
next;
}
}
转载于:https://blog.51cto.com/xiaochong/424681