0

我正在为我的 SSH 连接使用 Perl Expect 模块。我已经有一个使用这样的子功能的模块:

$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();
        }
],

但我的 $quotedhostname 是大写的。当它也是小写时,我需要抓住它。有没有办法做这样的事情:

[ qr/.*$quotedhostname.*/ OR /.*$lowercasequotedhostname.*/ => sub

还是我只需要添加另一个[qr]块?

4

1 回答 1

4

添加一个/i标志以使匹配不区分大小写:

[ qr/$quotedhostname/i => sub

您也不需要.*开头和结尾的,无论如何它都会匹配(它们只是在这里让它变慢)。

于 2014-08-01T14:48:23.893 回答