Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How to expect one of two patters using expect module. I want to expect one the two patters and continue to expect for one of the pattern.

Replies are listed 'Best First'.
Re: Expect pattern match
by ikegami (Patriarch) on Jun 28, 2005 at 16:14 UTC

    Like this?

    $exp->expect($timeout, [ qr/regex1/ => sub { my $exp = shift; ... $exp->send("response\n"); } ], [ qr/regex2/ => sub { my $exp = shift; ... $exp->send("response\n"); } ], ); $exp->expect($timeout, [ qr/regex1/ => sub { my $exp = shift; ... $exp->send("response\n"); exp_continue } ], );

    Alternatively,

    $first = 1; $exp->expect($timeout, [ qr/regex1/ => sub { $first = 0; my $exp = shift; ... $exp->send("response\n"); } ], [ qr/regex2/ => sub { return exp_continue_timeout unless $first; $first = 0; my $exp = shift; ... $exp->send("response\n"); } ], );

    Update: Part of my reply got accidently erased. Re-added the missing chunk.