Your long sequences of
$exp->expect...; $exp->send... are painful. The suggestion above about a dispatch table might be good, or perhaps you could just set up arrays for each subroutine. Something like this would make it a lot easier to see what's being done, and would make maintenance easier too. Here's an example based on the "now" sub:
sub now {
login();
my @comseq = (
[ 'Menu Selection', "8\r" ],
[ 'Menu Selection', "0\r" ],
[ 'Selection', "0\r\r" ],
[ 'Job File Name', "$job\r" ],
[ 'Batch Options?', "Y\r" ],
[ 'Display Batch Queues', "\r",
[ 'Notify Upon Completion?', "\r" ],
[ 'Queue Priority', "\r" ],
[ 'Scheduled Start Date', "\r" ],
[ 'Scheduled Start Time', "\r" ],
[ 'Batch Queue', "$queue\r" ],
[ 'Exception Item Batch ID', "\r" ],
[ 'Okay?', "Y\r" ],
[ "Batch Job $job Is Done", "\e" ],
);
for my $com ( @comseq ) {
$exp->expect( 10, '-re', $$com[0] );
$exp->send( $$com[1] );
}
$exp->send("\e");
$exp->send("\e");
logoff();
}
That said, I would also want to follow the other suggestions about having the subroutines take explicit args and return explicit values -- e.g.:
sub now {
my $exp = login( @_ ); # caller passes login args to us.
...
logoff( $exp );
UPDATE: BTW, if/when you need to use things other than 10 and '-re' as the first and second args on some "expect()" calls, just add those into the @comseq array -- e.g.:
my @comseq = (
[ 256, '-foo', 'Bar?', "baz\r" ],
[ 10, '-re', 'Yes or no?', "Can't decide\r" ],
...
);
for my $com ( @comseq ) {
my $send = pop @$com;
$exp->expect( @$com );
$exp->send( $send );
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.