in reply to Net::telnet difficulty

Please read the docs for a module before posting a question about it. I've never used Net::Telnet, but I spent less then 45 seconds skimming the docs before I found the answer to your question.

I'll give you a hint, grep for (and look at) all occurences of "Errmode" or "errmode".

Replies are listed 'Best First'.
Re^2: Net::telnet difficulty
by mosh (Scribe) on Aug 10, 2004 at 10:16 UTC
    I've read the docs but if you meant to use Errmode=>"return" it is not working, since the telnet doesn't die in case of T.O. What I want is that the telnet dies after T.O. but the perl script will continue and won't die too. Mosh.
      I am assuming that you want your code to perform a different action, and take a different path if the Net::Telnet object doesn't exist. One option is put your non-connected code into a function and then have that execute. For example:
      my $t = new Net::Telnet(..) || branch(args); #code to occur if the telnet session is established. exit; sub branch { #code here and bail out exit; }
      amt

      I never said to use Errmode=>"return" .. I said to read the docs and pay attention to every mention of Errmode. If you want to use Errmode=>"return" that's fine, but there are several other options.

      Since you didn't post any runnable code, no one can even begin to help you figure out why it's not working the way you want, we can only guess. Me, I spent about 2 minutes writting this, which seems to me to work just fine, so I have no idea what your problem is....

      #!/usr/local/bin/perl -l use strict; use warnings; use Net::Telnet; sub t { return scalar(localtime) . " - "; } print t(), "Starting"; my $tel = new Net::Telnet(); $tel->open(Host=>'www.yahoo.com', Port=>9000, Timeout=>10, Errmode=>'return') or print t(), "Couldn't Open: ", $tel->errms +g(); print t(), "Timed Out: ", $tel->errmsg() if $tel->timed_out(); print t(), "still going strong"; __END__ laptop:~> monk.pl Tue Aug 10 23:56:32 2004 - Starting Tue Aug 10 23:56:43 2004 - Couldn't Open: problem connecting to "www.y +ahoo.com", port 9000: connect timed-out Tue Aug 10 23:56:43 2004 - Timed Out: problem connecting to "www.yahoo +.com", port 9000: connect timed-out Tue Aug 10 23:56:43 2004 - still going strong laptop:~>