http://www.perlmonks.org?node_id=103292


in reply to Re: Quick and portable way to determine line-ending string?
in thread Quick and portable way to determine line-ending string?

$/ is set to "\n" by default. Which doesn't answer the question of "what is the representation of "\n" in external text files?".

This is the kind of thing that'll probably work but I was trying to avoid because it's hard to track and get right:

my $nativeSeparator = "\n"; if ($^O =~ /MSWin32|dos|os2|cygwin/) { # not sure what to do about cygwin here. $nativeSeparator = "\x0d\x0a" } elsif ($^O eq 'MacOS') { $nativeSeparator = "\x0d" } elsif ($^O eq 'VMS') { # it depends on file type... what to do? } elsif (ord('A') eq 193) { # what to do for EBCDIC? "\n" may be OK... }