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 | |
by ikegami (Patriarch) on Nov 06, 2021 at 00:55 UTC |