Your problem has to do with newline terminators. The telnet protocol requires that you use CRLF for newlines in both directions, and thus attempting to read a line until a \n (update: the default) will not work, because there will be an extra character (either at the beginning or end, depending on your platform). To fix this you can set $/ to \x0A\x0D (or \012\015 if you prefer, or you may import it from the Socket module with use Socket qw(:crlf) and then use $CRLF for this) so that <$filehandle> will read until CRLF, and so that you can use chomp to take it off the end of the string.

Also note that you should not output \n\r to end lines, because the value of the \n and \r is not portable across platforms. On Windows and UNIX perl it corresponds to NL and CR respectively, but on MacPerl it corresponds to CR and NL respectively. Best off using $CRLF from Socket for clarity, or just enter the hex or octal escapes.

And please use strict and warnings.


In reply to Re: Cant get user input from sockets into variables. by wog
in thread Cant get user input from sockets into variables. by thran

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.