Edited by Corion: Moved to Seekers Of Perl Wisdom

Okay, this is a strange thing that probably has a lot to do with the way I implemented IO::Socket. I have the following main body of code:
while ($new_sock = $sock->accept()) { ... while (defined ($buf = <$new_sock>)) { if ($buf =~ /^VERIFY:/) { if (verify_pass($buf)) { print $new_sock "VERIFIED\n"; } else { print $new_sock "NOT VERIFIED\n"; } ... ... } sub verify_pass { ($args) = @_; ($cmd, $user, $pass) = split(/:/, $args); chomp($pass); my $uid = getpwnam $user; my $pwd = (getpwuid $uid)[1]; my $salt = substr $pwd, 0; my $enc = crypt($pass, $salt); if ($enc eq $pwd) # Meaning success { return 1; } else { return 0; } }
Basically, the client sends to this server a command such as VERIFY:username:password. I know the verification routine works if I run it on its own. However, when I try this encryption, I keep getting NOT VERIFIED's on an account I use to test. When I output the contents of $pass in verify_pass I notice that a ^M is tagged on the end of it. If I chop($pass), then this character goes and the verification works. Is there a reason why the ^M appears? When I checked $buf in the main loop, the ^M was not there. Any help would be appreciated.

In reply to ODD IO::SOCKET by Anonymous Monk

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.