in reply to Next & Last - Perl's Expect

moot explained the problem. Here's how to work around it:

my $next = 0; $exp->expect(3600, [ qr/UNKNOWN TABLE/i, sub { my $self = shift; sleep(1); $self->send("abort\r"); $next = 1; }], [ qr/TABLE: $table/i, sub { my $self = shift; $self->send(""); }]); next if $next;

Replies are listed 'Best First'.
Re^2: Next & Last - Perl's Expect
by tc1364 (Beadle) on Apr 28, 2005 at 21:05 UTC
    This worked great! Thank you very much! So, the trouble was exactly what you mentioned being that the "next" command was not being reconginzed because it was in the Expect call.

      No, it has nothing to do with Expect. The problem was that the sub in which next was located did not have a loop. next doesn't work beyond a sub. That's because next is a keyword, not a function. Keywords have meaning at compile-time, but the caller of the sub is only known at run-time.

      Note that perl 6 will convert next into a special die, so it might work as you expected, depending on the guts of Expect.