in reply to can not use utf8 with File::Slurp

Looking at File::Slurp, it thinks binmode is only for cr/lf translation. It is broken that way, because it never calls binmode but does some fiddling with O_ flags and sysopen instead. I think it completely ignores PerlIO in favour of speed. My recommendation is to replace File::Slurp with:

sub write_file_utf8 { my $name = shift; open my $fh, '>:encoding(UTF-8)', $name or die "Couldn't create '$name': $!"; local $/; print {$fh} $_ for @_; };

This likely is a bit slower, but likely it works, as opposed to File::Slurp. You might also want to open a bug against File::Slurp.

Replies are listed 'Best First'.
Re^2: can not use utf8 with File::Slurp
by ikegami (Patriarch) on Feb 15, 2011 at 17:18 UTC

    I think it completely ignores PerlIO in favour of speed.

    Nit: sysopen doesn't stop PerlIO from being used. Either your Perl uses PerlIO or it doesn't. (Perl is built to use PerlIO by default since 5.8. I wouldn't be surprised if Perl didn't work without PerlIO anymore.) A given Perl only supports one kind of file handle. It doesn't matter whether you use open or sysopen.

    That doesn't mean there is no difference. When using O_TEXT on Windows, Perl might let clib do the LF⇒CRLF translation instead of using the :crlf layer. That could be faster, but I would hope it's not.