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 ); }

In reply to Re: code critique by graff
in thread code critique by puntme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.