Perl Monk, Perl Meditation | |
PerlMonks |
Re: Expect doesn't work as Expectedby jethro (Monsignor) |
on Jul 07, 2012 at 21:38 UTC ( [id://980521]=note: print w/replies, xml ) | Need Help?? |
Your regexp .* is the biggest problem here. .* matches everything, even the empty string! The module goes into an endless loop always matching the empty string and never advancing because nothing is matched or rejected, so new match rounds start at the same place. If you want to see how it works, change .* to .+ in your original script. Then you will see how it works and you will see sensible values printed for "after match string" and "before match string" I could get your script to work (although endlessly) by adding \n to your ->send strings and disabling your .* catch all or nothing regexp:
I suspect you will never get an 'eof' because units runs in an endless loop. You have to send the eof or control-d character to units or simply close the connection when the regexp /you have/ matches a second time, i.e. something like this works:
PS: Please use 'use warnings;' and 'use strict;'. No modern perl script is complete without them
In Section
Seekers of Perl Wisdom
|
|