$ perl -MEncode=_utf8_off -E'$_="\xC9ric"; _utf8_off($_); say;'
?ric
$ perl -E'$_="\xC9ric"; utf8::encode($_); say;'
Éric
The message said you had non-bytes in your string. The solution is to encode your text into bytes. The problem has nothing to do with the UTF8 flag. As you've found out, that can't be done via the binmode parameter, so you have to do your own encoding. This has noting to do with the UTF8 flag, and doesn't require any mucking into Perl internals.
Yet 'Encode' module is huge, so it is overkill also.
That's why I used utf8::encode instead of Encode::encode_utf8. That and the fact utf8::encode has the same calling convention as _utf8_off.
_utf8_on and _utf8_off should never ever be called. If you do need to muck with the internals to work around some XS bug, utf8::upgrade and utf8::downgrade will help. |