0

I'm using Perl Expect module for my SSH connections. I already have a module using sub functions like this:

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

But my $quotedhostname is UPPERCASE. I need to catch this when it is LOWERCASE too. Isn't there a way to do something like this:

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

Or should I just have to add another [qr] block ?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Gui O
  • 363
  • 4
  • 8
  • 22

1 Answers1

4

Add a /i flag to make the match case-insensitive:

[ qr/$quotedhostname/i => sub

You also don't need the .* at the start and end, it'll match anyway (they only serve to make it slower here).

Leeft
  • 3,827
  • 1
  • 17
  • 25