in reply to Re: Have trouble implementing a shell-alike script
in thread Have trouble implementing a shell-alike script

When Perl writes to Windows, a \n is CRLF. When Perl writes to a network socket, a \n is CRLF.

No. See http://search.cpan.org/~jesse/perl-5.14.1/pod/perlport.pod#Newlines, binmode

  • Comment on Re^2: Have trouble implementing a shell-alike script

Replies are listed 'Best First'.
Re^3: Have trouble implementing a shell-alike script
by Marshall (Canon) on Sep 14, 2011 at 10:04 UTC
    Thank you for making my point. If you click on your own link, you will see the below.
    A common misconception in socket programming is that \n eq \012 everywhere. When using protocols such as common Internet protocols, \012 and \015 are called for specifically, and the values of the logical \n and \r (carriage return) are not reliable.
    The link gives examples:
    print SOCKET "Hi there, client!\r\n"; # WRONG print SOCKET "Hi there, client!\015\012"; # RIGHT <- also wrong!
    The \r is wrong. I think that:
    print SOCKET "Hi there, client!\n"; #WORKS, on Unix or Windows!! #sends CR/LF: \015\012
    Basically do not ever put \r (CR) in a print statement. I agree.
    For the \n in the source code, Perl will send either LF or CRLF depending upon what it is taking to.

      Thank you for making my point. If you click on your own link, you will see the below.

      And incredibly, in the line right after the one you quoted it says

      print SOCKET "Hi there, client!\r\n"; # WRONG print SOCKET "Hi there, client!\015\012"; # RIGHT

      Keep reading smartalec

        Before this escalates, please step back, make your point with code and data, and don't resort to names. They do nothing to prove your point.

        --MidLifeXis

        So anonymous smartalec, post some code that proves your point.

        I think that it is beyond discussion that Perl prints LF for \n on a Unix system and Perl prints CRLF for \n on a Windows system. I further claim that Perl will print CRLF for \n on a Network socket.