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

John M. Dlugosz has asked for the wisdom of the Perl Monks concerning the following question:

I found an interesting issue when running under Windows where "normal" text files have CRLF line endings.

Basically, using a generated temporary file from File::Temp was not giving the normal endings, but were "binary" by default.

use File::Temp; use File::Spec; print "hello1\n"; # defaults to CRLF, as documented. open F, ">", "out2.txt"; # ditto. print F "hello2\n"; open F, "> :utf8", "out3.txt"; # still CRLF print F "hello3\n"; open F, ">", "out4.txt"; binmode F, ":utf8"; # still OK! print F "hello4\x{b6}\n"; $h= new File::Temp( TEMPLATE => 'helloXXXXX', SUFFIX => $suffix, UNLIN +K => 0, DIR => File::Spec->tmpdir()); $fname= $h->filename; print "sending out5 to $fname\n"; # binmode $h, ":utf8"; # no CR, shows 0x0A only. But :utf8 silences +warning. print $h "hello5\x{b6}\n";
Looking at the Perl code for File::Temp, I see that it uses sysopen rather than the normal open. I think that's why it behaves differently.

Why?

And why does sysopen not set up the platform defaults, though it still appears to use IO layers?

—John

Update: behavior on Perl 5.8.4 (ActiveState build 810), but is fixed in Perl 5.8.6 (AS build 811)