A few more things:

Use lexial filehandles, the 3 argument form of open and check for success, so rather than

open(OUT, ">>telnet.log");
Do it like this:

open my $out, ">>", "telnet.log" or die $!;

Then "$ip" is a useless interpolation - just use $ip.

Your "next" in the error-sub is not needed.

You open OUT both in the main-script as well as in the error-sub which won't hurt but does not achieve anything.
Depending on what you want you could either open it once and re-use the filehandle for every error, or open it for every error. If you use lexial filehandles you can open it once in the main script and reference it in the error-sub (get rid of the open there and just do "print $out "Bad connection...".)

On a more general note you should not hard-code filenames into your script as you loose a lot of flexibility (e.g. every time you run your script you overwrite the previous error-log - maybe you want to see how that changes over time).
A better approach would be to pass in the input-filename on the commandline (using "iplist1.txt" as a default) and print the errors not to a file but to STDOUT.
In this way the user of your script can decide where the error-log goes to (he could simply redirect the script-output to a file of his choosing).

Lastly use better variable-names (e.g. $error_log rather than "OUT") - you'll be glad later.


In reply to Re^3: Telnet list of IP and get information stored to a file by morgon
in thread Telnet list of IP and get information stored to a file by sanju7

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.