georgecarlin has asked for the wisdom of the Perl Monks concerning the following question:
I'm a perl beginner and trying to improve the re-usability of my code
I have a question regarding expect.pm, specifically how to create an abstract expect call.
Take this example:
@expectthese = ("pattern1", "pattern2", "pattern3"); @sendthese = ("string1", "string2", "string3"); $exp->expect($timeout, [qr/$expectthese[0]/, sub { select(undef, undef, undef, 0.25); $exp->send("$sendthese[0]"); do_stuff...} ], [qr/$expectthese[1]/, sub { $exp->send("$sendthese[1]"); select(undef, undef, undef, 0.25); do_other_stuff...} ], [qr/$expectthese[2]/, sub { $exp->send("$sendthese[2]"); select(undef, undef, undef, 0.25); do_this_stuff...} ], );
In this example expect simultaneously waits for 3 patterns to occur and then the respective stuff is done... How would I go about creating an abstract Block that would work in above way for @expectthese and @sendthese without pre-defining the amount of elements these arrays have and consequently without knowing how many [qr//,sub {do_stuff;}], blocks are needed?
Thanks in advance
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: abstract expect call
by kcott (Archbishop) on Oct 26, 2013 at 03:58 UTC | |
by georgecarlin (Acolyte) on Oct 28, 2013 at 10:26 UTC | |
|
Re: abstract expect call
by smls (Friar) on Oct 25, 2013 at 22:33 UTC | |
by georgecarlin (Acolyte) on Oct 28, 2013 at 10:21 UTC | |
|
Re: abstract expect call
by stonecolddevin (Parson) on Oct 25, 2013 at 21:48 UTC |