我写了一个函数来在远程机器上执行一个命令。带参数的perl函数调用
Command : iptunnel add obs mode gre remote x.x.x.x local X.X.X.X ttl 225 $okey $ikey
$okey $ikey
值作为参数传递。
现在,有时我想执行命令WITHOUT $ okey和$ ikey值。
Command : iptunnel add obs mode gre remote x.x.x.x local X.X.X.X ttl 225
现在我的问题是,我如何通过$ okey和$ ikey值作为可选参数。如果$ okey和$ ikey值不通过,那么必须执行下面的命令。
iptunnel add obs mode gre remote x.x.x.x local X.X.X.X ttl 225
如果传递$ okey和$ ikey值,则必须执行以下命令。
iptunnel add obs mode gre remote x.x.x.x local X.X.X.X ttl 225 $okey $ikey
功能:
sub gre_testing {
my ($self,$okey,$ikey) = @_;
$self->execute('iptunnel add obs mode gre remote x.x.x.x local X.X.X.X ttl 225 $okey $ikey');
return 1;
}
函数调用:
gre_testing(1000,1000);
单引号不插入变量时,你会得到一个错误。使用双引号。 – choroba
'我($ self,$ okey,$ ikey)=(@_,(“”)x 3 - @ _);' –
@Сухой27这有点让人困惑。至少对我来说:| –