in reply to Perl's Expect - foreach loop

What happens after it does the first command? Hang until timeout? Repeatedly executes first command?

Is there always a '>' in the prompt? If so, you might need to change the order of your list of matches. You might also look at exp_continue. I'm just guessing.


Caution: Contents may have been coded under pressure.

Replies are listed 'Best First'.
Re^2: Perl's Expect - foreach loop
by tc1364 (Beadle) on Apr 28, 2005 at 18:22 UTC
    The first command is only executed for each $table in @tables. Regarding the exp_continue command, this was tried but in would just keep cycling on the first $table. The command prompt is ">".
      Still guessing, but I think what you want is multiple calls to expect, one for each time you want it to respond to something you've sent:
      $exp->expect(180, [ qr/>/i, sub { my $self = shift; sleep(1); $self->send("TABLE $table; FORMAT 132 PACK\r"); }]); $exp->expect(180, [ qr/UNKNOWN TABLE/i, sub { my $self = shift; sleep(1); $self->send("")ort\r"); next; }], [ qr/TABLE: $table/i, sub { my $self = shift; $self->send(""); }]); ...etc...

      Caution: Contents may have been coded under pressure.
        You were right, the multiple calls worked fine. I sincerely appreciate the assistance you have provide me, thank you very much!
        You were right, the multiple calls worked fine. I sincerely appreciate the assistance you have provided me, thank you very much!