문제

I am actually refactoring the code of some of my co-workers and i have a question. Searching the web didn't gave me anything good so there it is :

I am spawning a new Expect to connect to every router & switch. Each time it connects, the expect works like this :

  $exp->expect ($timeout, 
        [qr/[Pp]assword:\s*/ => sub { 
            #Some work 1
        }],
        [qr/.*Are you sure you want to continue connecting.*/ => sub { 
            $exp->send("yes\n");
            exp_continue;
        }],
        [qr/.*refused.*/ => sub { 
            # some code 3
        }],
    );

I want it to start again from the first statement, probably need some recursion. When "exp_continue" is reached, what happens? will it start from the first qr/ or will it continue to the third?

Thanks

도움이 되었습니까?

해결책

Never worked with the perl expect package but according to the author it closely resembles expect.

Extract taken from Exploring Expect by Don Libes:

When executed as an expect action, the command exp_continue causes control to be continued inside the current expect command. expect continues trying to match the pattern, but from where it left off after the previous match. expect effectively repeats its search as if it had been invoked again.

A quick test would be to have it check for the password regex before and after the connection regex, and then displaying a msg to show which block was executed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top