in reply to File I/O while using Sockets?

If you're using 'telnet' to connect to port 9000, be aware that telnet will interpret your newlines as "\x0d\x0a", not a straight Perl \n. Thus, chomp will only rid you of the "\x0a" (what \n evaluates to under Unix, as in $/). Try either setting $/ to "\x0d\x0a" while processing data from the socket like that, use chop twice, or just use this regexp: s/\x0d\x0a$//;

When in doubt, I've been known to simply do this when I don't know how the lines end: s/[\r\n]+$//;

In addition, your print statement to OUT doesn't have a trailing newline, so your log file doesn't have an end-of-line to act on (stdio buffering does this, I believe). That's probably why you aren't seeing any of this ending up in the log file.

Replies are listed 'Best First'.
Re: Re: File I/O while using Sockets?
by jgallagher (Pilgrim) on Nov 22, 2000 at 06:29 UTC
    Thanks, that did it. Just to check, it won't produce any funky side-effects to chomp; after the regexp to rid any newlines from any non-telnet clients, will it?
      See the documentation for chomp. It only affects a string if there's the value of $/ at the end. It's "safe" like that.
      Nope. =)

      --
      $you = new YOU;
      honk() if $you->love(perl)