From: Roland G. <rgi...@cp...> - 2007-03-20 10:22:43
|
how about my $promptRE = join("|", keys %args); $exp->expect($timeout, [ qr/^($promptRE) /, sub { $self = shift; my $prompt = ($self->matchlist())[0]; $self ->send($args{$prompt}, "\n"); exp_continue } ], ); to use a list of responses in the hash to be able to handle multiple occurances of the same prompt is left as an exercise to the reader... :-) On 3/20/07, John Bradshaw (Lists) <li...@jo...> wrote: > Hi all, > > Trying to drive an interactive session with some telecomms kit. It's a > very simple interface - it gives a series of fixed prompts to which the > user enters a response, nothing fancy but quite tedious. > > I have a Perl hash with the prompts as keys and the responses as the > hashed values. > > Example of a session... > REQ NEW > TYPE TIE > CUST 0 > ... > where REQ, TYPE and CUST are the kit's prompts - always on a new line > ending with a space. NEW, TIE and 0 are the corresponding responses. > > So the draft code is... > > $exp->expect($timeout, > [ > qr/^REQ /, > sub { > $self = shift; > $self ->send($args{"REQ"}, "\n"); > exp_continue > } > ], > [ > qr/^TYPE /, > sub { > $self = shift; > $self ->send($args{"TYPE"}, "\n"); > exp_continue; > } > ], > [ > qr/^CUST /, > sub { > $self = shift; > $self ->send($args{"CUST"}, "\n"); > exp_continue; > } > ], > # Hundreds more patterns here... > ... > ... > ); > > This works fine however I'd like to build the expect loop during > execution using the %args hash as it's easier to add hash pairs than > have to modify code when a new prompt appears. > > Is this supported with Expect.pm? If so, any hints on the best way to > code this? > > Thanks, > John. > > > > ------------------------------------------------------------------------- > Take Surveys. Earn Cash. Influence the Future of IT > Join SourceForge.net's Techsay panel and you'll get the chance to share your > opinions on IT & business topics through brief surveys-and earn cash > http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV > _______________________________________________ > Expectperl-discuss mailing list > Exp...@li... > https://lists.sourceforge.net/lists/listinfo/expectperl-discuss > |