keenlearner has asked for the wisdom of the Perl Monks concerning the following question:
The units executed in the terminal will print theseuse Expect; $Expect::Debug = 3; # verbose debug output $Expect::Log_Stdout = 1; # show chatter for debugging $Expect::Exp_Internal =1; my $exp = Expect->spawn("units") or die "Cannot spawn unit: $!\n"; $exp->log_stdout(1); $exp->expect(15, [ qr/you have/i => sub { my $exp = shift; print "you have"; $exp->send("2 km"); exp_continue; } ], [ qr/you want/i , sub { my $exp = shift; print "you want"; $exp->send("m"); exp_continue; }], [ 'eof', sub { my $exp = shift; print "eof"; print +$exp->before(); } ], [ qr/.*/, sub { my $exp = shift; print $exp->error; print $exp->before(); } ] );
In the log it shows thisuser@dell:~> units 2526 units, 72 prefixes, 56 nonlinear units You have:
Before match string: `' Why does it show `' ? what is that string ? And what is wrong with the code ? Thanksspawn id(20): Does `' match: pattern #1: -re `(?^i:you have)'? No. pattern #2: -re `(?^i:you want)'? No. pattern #3: -eof `'? No. pattern #4: -re `(?^:.*)'? YES!! Before match string: `' Match string: `' After match string: `' Matchlist: () Calling hook CODE(0x7fd8217449c0)... Returning from expect successfully. spawn id(20): accumulator: `' Closing spawn id(20).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Expect doesn't work as Expected
by jethro (Monsignor) on Jul 07, 2012 at 21:38 UTC | |
by keenlearner (Acolyte) on Jul 08, 2012 at 06:45 UTC | |
by jethro (Monsignor) on Jul 08, 2012 at 13:37 UTC | |
by keenlearner (Acolyte) on Jul 10, 2012 at 03:10 UTC | |
|
Re: Expect doesn't work as Expected
by zentara (Cardinal) on Jul 09, 2012 at 18:00 UTC |