Looking for a way to chomp newline characters irrespective of the platform the files were created on.
The problem as specified by perlport#newlines is that newlines are encoded differently on each platform:
\012 unix
\015\012 windows
\015 mac
However, chomp is platform specific and will only remove the character for the platform it's running on, or anything set by the $/
variable.
So far I came up with the following regex that seems to be working:
# multiplatform chomp
s/\015?\012?$//;
Is that the correct solution or am I missing some cases and there's a better one?