in reply to Re: Remove new line characters
in thread Remove new line characters

notepad.exe displays new-line characters as 'boxes' if not prefixed by '\r'. Although it could be argued that it hardly qualifies as a 'display tool'. wordpad.exe can handle this format.
I would have thought that the simplest (though not necessarily most efficient) way of getting rid of new-lines at the end of text was:
() while chomp $line;

Replies are listed 'Best First'.
Re^3: Remove new line characters
by graff (Chancellor) on Apr 17, 2007 at 14:51 UTC
       () while chomp $line;

    That would only work if $/ happens to match whatever is at the end of the line. If it really is just a matter of one or more "\n" with no preceding "\r", then you would do:

    s/(?<!\r)\n+//g; # should probably leave "\r\n" as-is
    which would work no matter what $/ happens to be.

    As for notepad.exe displaying a box to represent "\n" when it is not preceded by "\r", that's an interesting point that I was not aware of. But I would still expect that it also uses the box to represent other code points for which the current font does not have a defined glyph -- in other words, the box is ambiguous: there might be a variety of different byte values (code points) that would cause it to appear.

    And yes, notepad.exe is a display tool, in the sense that it makes data visible to the user. But since it's also a text editor, it makes certain assumptions about what the user is interested in seeing. (And the same goes for wordpad.exe)