[Israel.pm] newline character as a portability issue

Alex Behar alex-b at actcom.net.il
Thu Jul 8 03:18:31 PDT 2004


On Wednesday 07 July 2004 19:27, Shlomo Yona wrote:
> Hello,
>
> 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 know that on unices that '\n' is the newline. I don't
> really know if that is always the case, and I also don't
> know what happens on other platforms.
>
> What would be a good way to attack this issue?
> Once I have a solution, what would be the way to write tests
> (using Test::More) to ensure that during installation (say,
> during 'make test')? I mean, how can I make a platform
> dependent test for this issue?
>
> Thanks.

Perl using just "\n" is portable enough. Meaning, if it's an active-perl 
installation, it will match the windows style line termination. If its a UNIX 
perl, it will match the UNIX newline.
If you run a file made on a windows machine, and you try to match the new 
lines in a UNIX perl installation, it will work. I have not tested the case 
from UNIX to windows, I dont have a windows box handy.

Best regards,
Alex



More information about the Perl mailing list