When I do:
use IO::Async::Stream;
$tty = IO::Async::Stream->new(
read_handle => \*STDIN,
write_handle => \*STDOUT,
on_read => \&tty_read,
);
I get error: Constructing a IO::Async::Stream with an encoding-enabled handle may not read correctly
On other host same code works fine.
Why on this host I get this error and how to fix it?
CodePudding user response:
Ok. This is different host and only environment could differ. So I did:
# env | grep PERL
PERL_UNICODE=SA
PERL5LIB=/usr/local/proj/lib:/usr/local/proj/local/lib/perl5:
Then I did $ unset PERL_UNICODE
and my script works fine now.
See documentation here about PERL_UNICODE
CodePudding user response:
It appears that IO::Async::Stream expects a "raw" file handle, but you are providing one with an encoding layer attached.
you might by using the following:
use open ':std', ':encoding(UTF-8)';
If so, replace it with the following:
use open ':encoding(UTF-8)';
BEGIN {
binmode( STDERR, ':encoding(UTF-8)' );
}
To deal with decoded text, you'll also need to decode or encode the data received from and passed to $tty
, say by using the encoding
constructor parameter. You can't simply pass the text received by on_read
to decode
as it might contain a partial character.