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

I know it is somewhat off-topic, but allow me to discuss newlines on windows. Windows disk files use the pair of ASCII characters CR,LF as a newline. When we run perl on windows, the IO layer 'crlf' is active by default (ref open}. On input, this layer translates the CR,LF to a single \n character. On output, it translates perl's \n to the CR,LF pair and writes both to the disk (ref doc:\\perlIO--link available in open). There is no \r for a regex to find. The binmode function is provided to turn off this processing when we really need the \r's. (The easiest way to process windows files on UNIX is to explicitly specify this layer in the open statement.)
Bill
  • Comment on Re^4: How do I display only matches (updated)

Replies are listed 'Best First'.
Re^5: How do I display only matches (updated)
by Marshall (Canon) on Sep 25, 2019 at 21:36 UTC
    Hi BillKSmith,

    I can see that there is a need for a FAQ on line endings.
    I'd be willing to cooperate with you on such a project?

    There are various cases involving reading a Unix file on Windows, reading Windows file on Unix.
    Other demos should include that <CR><LF> as standard network protocol.
    I have never used binmode to account for \r (<CR>). there are other ways.

    Any combine our ways together to make a FAQ?

    Update: I see that there are some detailed explanations of :CRLF layer, etc.
    A simple "how to" for reading and writing Mac,Unix,PC files on any of the platforms could be helpful.

      A FAQ sounds like a good idea to me. I have no idea of the mechanics of how to create one. A FAQ is usually little more than an example of "how to...". That seems to be appropriate in this case. The more detailed discussion that you proposed belongs somewhere else, perhaps a tutorial.

      I suspect that Perl's concept of 'layers'(with appropriate defaults) works so well that most of us are not even aware that it exists. I had used perl for over fifteen years before I even read 'PerlIO'. (I still have not read all the documentation for open.) The issue came up when Laurent_R and I were helping someone on the old PerlGuru.com. We could use his help.

      Bill
        Yes, there appears to be quite a controversy about what print "\n"; means when using the defaults on various platforms.

        Perl's behaviour for me is easy to understand for write: a)Old Mac <CR>, b) Unix <LF>, c) Windows <CR><LF>.

        I believe that when writing to a network socket, <CR><LF> is used, whether a), b), or c).

        For the most part Perl hides these details (except when it doesn't).
        That there is such controversy about such a seemingly simple thing implies that a FAQ is needed.