deepblue has asked for the wisdom of the Perl Monks concerning the following question:
I am a user of Expect.pm module. I am in love with Expect.pm.
Recently I came across a situation wherein I felt the need for support for a single line (m/<RegEx>/s) regular expression matching when the arguments to expect are similar to:
$object->expect ($timeout, ‘-re’, <some pattern>);
The situation wherein I felt this need follows –
I have a shell script to install software on UNIX. This script keeps on prompting the user for answers to its questions. The user then provides the answers.
Between 2 consecutive questions, there is some multiple line text printed on screen as shown in the snippet below. The next question is displayed once the current one is answered. And the script goes this way when run manually.
So, every time, the last line in all the multi-line text displayed is the line having question. And I have to get this question using regular expression or anything similar so that I can provide the corresponding answer using some pattern matching. If this is done using the normal multi-line matching regular expression feature provided ($Expect::Multiline_Matching), this matches many intermediate lines and thus the automation script is not that efficient and fails at a later stage.
Instead, if a single line matching support is provided, the last line can be directly extracted using a regular expression as simple as:
qr/^(.*)\n(.*)$/s
Also, in all the user interaction programs, the last line would be a question / prompt. Hence this enhancement would greatly simplify the automation script’s design.
Please Note: The text that is a question is the question the user has to answer, and the text after that question is the corresponding user response/answer.
Snippet from the install script:
-------------------------------------------
……. and so on…Bash-2.05$ ./Install.sh This software uses the MD5 message digest algorithm for authentication. The source code used to implement this function is derived from the RSA Data Security, Inc. MD5 Message Digest Algorithm, published in RFC 1321. Are you ready to proceed? (yes/quit) [yes]: Y Software Installation ======================= What is the Unix username? [root] rkabra What is this host's Domain Name? xyz.com Software will be installed with the following settings: ======================================================== Unix username rkabra This host's DNS Domain Name xyz.com This will be a simplified install no Do you accept these settings? (Yes/No/Quit) [yes] Y
Availability for multi-line matching is already present. Users of Expect.pm would really appreciate if support for single line match is also incorporated / added.
Is there any other way (a workaround) to overcome the problem I am having? If yes, could you please let me know?
Thanks in anticipation.
Regards,
~DeepBlue
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need a solution to Expect.pm 's single line regex matching limitation
by RaduH (Scribe) on Nov 16, 2007 at 20:33 UTC | |
|
Re: Need a solution to Expect.pm 's single line regex matching limitation
by Argel (Prior) on Nov 17, 2007 at 01:23 UTC | |
by deepblue (Initiate) on Nov 17, 2007 at 10:40 UTC | |
by shmem (Chancellor) on Nov 17, 2007 at 23:49 UTC | |
by deepblue (Initiate) on Nov 18, 2007 at 03:41 UTC |