in reply to code critique
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 { 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(); }
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 ); }
|
|---|