A handy tool for checking weird output is the od command. If you pipe your output to od -c you will see all the non-printing characters. When I did this with your server (having added a print of what came in to $buf from the socket) I saw the following.

0000000 L i s t e n i n g f o r c +o 0000020 n n e c t i o n s o n p o +r 0000040 t 8 8 8 8 \n b u f = " C +S 0000060 C \r " \n 0000064

Applying the fix oshalla recommended solved the problem.

The od command is usually installed on *nix systems and is available for Windows.

I note also that you are interpolating whatever text you receive from the socket into your SQL statement without any validation. Consider what will happen if a nasty fragment of SQL was entered rather than a group name. You might lose data.

A good habit is to always check your data from external sources to make sure it is valid. And you might use place holders in your SQL statement rather than interpolating the group name into the string to further reduce the risk.


In reply to Re^3: IO::Socket and passed variables to functions by ig
in thread IO::Socket and passed variables to functions by onegative

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.