[Israel.pm] newline character as a portability issue

David Baird david.baird at homemail.com
Sun Jul 11 00:17:45 PDT 2004

> I have a script which does some manipulation to texts.
> This script assumes that '\n' is the newline character.
> I wonder how I can make the script more robust across
> platforms, regarding newline characters.


I rarely say this, but since I know you are a veterin to this list, and
a general expert on Perl, I say: RTFM!

Read perlport, the first issue discussed is newlines. Hey, who'd of
thought that the people who wrote Perl also took newline characters into
serious consideration!

A summary is, if you don't try to tear appart Perl, and don't try to
analyize it too hard, it does the right thing 99% of the time. Use \n
and you will be portable. When you DON'T want to be portable, set your
IO stream with binmode(), and handle the newline sequences manually.

There is only ONE case where I had trouble with newline portability: The
Tie::File module reading Unixy files from a script running on Windows,
but this is because MJD is being very clever, and completely bypassing
all the built-in IO layering of Perl.


More information about the Perl mailing list