如何在Perl';s qr/?
我正在使用Perl Expect模块进行SSH连接。我已经有了一个使用如下子函数的模块:如何在Perl';s qr/?,perl,expect,tolower,toupper,Perl,Expect,Tolower,Toupper,我正在使用Perl Expect模块进行SSH连接。我已经有了一个使用如下子函数的模块: $exp->spawn("ssh -o ConnectTimeout=$connectTimeout $user\@$ip") or die ("unable to spawn \n"); @obj=$exp->expect( $commandTimeout, [ qr/.*$quotedhostname.*/ => sub { print "connect
$exp->spawn("ssh -o ConnectTimeout=$connectTimeout $user\@$ip") or die ("unable to spawn \n");
@obj=$exp->expect( $commandTimeout,
[ qr/.*$quotedhostname.*/ => sub
{
print "connected \n";
$exp->send("term length 0", "\n");
$exp->expect($commandTimeout2,);
&executeCommands();
}
],
[ qr/.*$quotedhostname.*/ OR /.*$lowercasequotedhostname.*/ => sub
但是我的$quotedhostname是大写的。当它也是小写时,我需要捕捉它。
难道没有办法做到这一点吗:
$exp->spawn("ssh -o ConnectTimeout=$connectTimeout $user\@$ip") or die ("unable to spawn \n");
@obj=$exp->expect( $commandTimeout,
[ qr/.*$quotedhostname.*/ => sub
{
print "connected \n";
$exp->send("term length 0", "\n");
$exp->expect($commandTimeout2,);
&executeCommands();
}
],
[ qr/.*$quotedhostname.*/ OR /.*$lowercasequotedhostname.*/ => sub
或者我应该只添加另一个
[qr]
块吗?添加/I
标志以使匹配不区分大小写:
[ qr/$quotedhostname/i => sub
您也不需要在开始和结束时使用
*
,它无论如何都会匹配(它们只会使它在这里变慢)。添加/i
标志以使匹配不区分大小写:
[ qr/$quotedhostname/i => sub
您也不需要在开始和结束时使用*
,它无论如何都会匹配(它们只会使速度变慢)