I have a small program (see below) that connects to a network power switch and turns power on and off (NetSwitchOn();). If another connection is made prior to yours the unit will reject the connection. I have added an error handler (Errmode => sub {&errorHandler()},) but the problem is that if the second sub call trys to turn on the power and if there is an error I only get one loop and then the progress bar, not retrying the telnet connection. The first call will retry until the connection is made.
--------------------code below --------------------------- # Power switch on sub # This will connect to a network power switch and apply power to the u +ut # Author: # Date: 6/2/04 # Rev: 01 sub NetSwitchOn { print <<EOB; Turning on the UUT.... ;-) EOB $telnet = Net::Telnet->new( Host => $PS2, Port => 23, Prompt => '/[$%#>] $/', Errmode => sub {&errorHandler()}, Input_log => $pwr_log, Dump_log => $dumpPW_log, ) or "return"; print "Connected to Power Switch: ", $PS2, "\n"; print "-" x 40, "\n"; $telnet->print ('/on 1'); ok ($telnet->waitfor('/Processing - please wait/'), "Turning on th +e power switch"); ok ($telnet->waitfor('/Complete/'), "Unit is on"); $telnet->print ('/x'); $telnet->close; print "Connection closed: ;-( \n "; print "-" x 40, "\n"; } #--------------------------------------------------------------------- +--------# # This routine will handle the telnet object errors. #--------------------------------------------------------------------- +--------# sub errorHandler { print "Another system must be connected..\n"; print "Will retry in 5 seconds..\n"; sleep 5; redo; }

In reply to net::telnet errmode issue by smurray

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.