Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top