in reply to Re^8: How do I display only matches
in thread (SOLVED) How do I display only matches

I believe that the confusion here is that the standards specify use of <CR><LF> (as far back as RFC139, page 3, on a quick check) but *nix has a far simpler I/O model than was contemplated for the systems on the early ARPAnet. (ASCII itself is RFC20, by the way.)

So for correct and portable network usage, you are supposed to use "\015\012" rather than "\n" anyway, although Perl's ":crlf" PerlIO layer should cause "\n" to be emitted as "\015\012". Confused enough yet?

Replies are listed 'Best First'.
Re^10: How do I display only matches
by Marshall (Canon) on Sep 27, 2019 at 23:04 UTC
    Thank you for the RFC reference.
    I believe that you are correct and that Perl's default text I/O layer will do what you say.
    I currently don't have a UNIX system to test with, but yes, this is "the way it is supposed to work".

    I someone is writing both ends of a client/server application, of course you can do whatever you want.You can even just send a binary packet.

      Note that on *nix, the "default text I/O layer" is probably effectively :raw and :crlf is not used unless requested, because the Unix convention is that text files store only <LF> at end-of-line and "\n" is <LF> in POSIX.

      And the reason that you are supposed to specifically say "\015\012" instead of "\r\n" is that the latter is the current platform's notion of "carriage return/line feed" and might not be the ASCII CR/ASCII LF that is supposed to be used on the network. (I seem to recall that classic MacOS interpreted "\r\n" as "\012\015" as one example. I suspect EBCDIC systems may be even more bizarre.)

      Edited 2019-10-01 by jcb: Clarify wording to address haukex's nitpick.

        Note that on *nix, the "default text I/O layer" is probably :raw and :crlf is not used unless requested

        A bit of a nitpick, from PerlIO:

        :raw
        ... The implementation of :raw is as a pseudo-layer which when "pushed" pops itself and then any layers which do not declare themselves as suitable for binary data.

        The defaults on 5.28:

        $ perl -wMstrict -MData::Dump -e "dd PerlIO::get_layers(STDOUT)" ("unix", "perlio") C:\>perl -wMstrict -MData::Dump -e "dd PerlIO::get_layers(STDOUT)" ("unix", "crlf")

        Update: There appears to be a a bug in PerlIO::get_layers() that causes the :crlf layer to always be reported on Windows, even after a binmode. (But the PerlIO documentation does confirm the above defaults.)