As I gathered from your comment in the CB, you specifically want to know if you failed to login. Well, the docs from Net::Telnet say:

login:
This method performs a standard login by waiting for a login prompt [...]. If any of those prompts sent by the remote side don't match what's expected, this method will time-out, unless timeout is turned off.

On success, 1 is returned. On time out, eof, or other failures, the error mode action is performed. See errmode().

errmode:
This method gets or sets the action used when errors are encountered using the object. [...] The second calling sequence sets it to $mode and returns the previous mode. Valid values for $mode are "die" (the default), "return", a coderef, or an arrayref.

When mode is "die" and an error is encountered using the object, then an error message is printed to standard error and the program dies.

When mode is "return" then the method generating the error places an error message in the object and returns an undefined value in a scalar context and an empty list in list context. The error message may be obtained using errmsg().

When mode is a coderef, then when an error is encountered coderef is called with the error message as its first argument. Using this mode you may have your own subroutine handle errors. If coderef itself returns then the method generating the error returns undefined or an empty list depending on context.

[Text on arrayref snipped]

errmsg:
most recent error message
$msg = $obj->errmsg;
The first calling sequence returns the error message associated with the object.
Perhaps it's just me, but that seems pretty clear? Don't set errmode, and the script will die. Set it to "return", and in case of an error, login() will return undef. Check $telnet->errmsg to see what failed.

p.s.: You should check out the EXAMPLES section of these docs. The examples given are pretty neat.

In addition, the chapter on Net::Telnet (and Net::FTP) from Lincoln Stein's book "Network Programming with Perl" is online. You can get the sample code here.


In reply to Re: Net::Telnet-Retrieving error information by bart
in thread Net::Telnet-Retrieving error information by frankjd5

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.