in reply to Dealing with files with differing line endings

All the systems you mentioned use CR LF or LF (unless you meant the ancient MacOS which used CR).

So just use LF as the line terminator as usual, but use something like s/\s+\z// instead of chomp.

while (<>) { s/\s+\z//; ... }

Alternatively, you could add a :crlf layer to the handle.

open(my $fh, '<:crlf', $qfn) or die("Can't open \"$qfn\": $!\n"); while (<$fh>) { chomp; ... }

This already happens by default on Windows, which is why it can handle the listed file formats naturally.

Replies are listed 'Best First'.
Re^2: Dealing with files with differing line endings
by dd-b (Pilgrim) on Nov 05, 2021 at 21:21 UTC
    Good point! I was jumping back to a more general question than I need to solve. As you say, I can just force LF for line boundaries. Parsing the contents can handle various line separators with \R, I think it already does (or I could do my own chomp with suitable regexp to kill all kinds of line terminators).

      As you say, I can just force LF for line boundaries

      No need to force anything. $/ is already a LF on all systems except ancient MacOS. Just replace chomp; with s/\s+\z//;.