If it works without binmode
set, then perhaps you have a solution (if not a real answer to why this is happening). c.f. this extract from perldoc -f binmode
:
On some systems (in general, DOS- and Windows-based systems) binmode() is
necessary when you're not working with a text file. For the sake of portability
it is a good idea always to use it when appropriate, and never to use it when it
isn't appropriate. Also, people can set their I/O to be by default UTF8-encoded
Unicode, not bytes.
In other words: regardless of platform, use binmode() on binary data, like
images, for example. ...
In the inimitable style of perldoc
I think that might be suggesting you could set binmode
for certain filehandles/sockets and not for others adjusting until the "bug" (if it is one) does not appear.
EDIT:
Thanks to your simple and reproducible error / test case I think this will get fixed. I built a debug version of perl
to try tracing the error and it is in liberperl.so
- somewhere in PerlIOBase_dup()
. I also mentioned this on IRC to people who would know, and they concluded this is a real (i.e reportable) perl
bug.
Here's how I ran gdb
:
(gdb) run -Dx -le 'use PerlIO::via::QuotedPrint; binmode(\*STDERR,
":via(PerlIO::via::QuotedPrint):utf8"); open (ERROR, ">&STDERR");'
and this was how things ended up:
Program received signal SIGSEGV, Segmentation fault.
PerlIOBase_dup (f=0x0, o=0x801551060, param=0x0, flags=2) at perlio.c:2307
2307 PerlIOBase(f)->flags |= PERLIO_F_UTF8;
Cheers, you made perl
better!