I Have The following block in the beginning of my script:
#!/usr/bin/perl5 -w
use strict;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
In some subroutines when there is other encoding(from a distant subroutine), the data will not display correctly, when receiving cyrillic or other characters. It is the "binmode", that causes the problem.
Can I "turn off" the binmode utf8 locally, for the subroutine only?
I can't remove the global binmode setting and I can't change the distant encoding.
One way to achieve this is to "dup" the
STD
handle, set the duplicated filehandle to use the:raw
layer, and assign it to a local version of theSTD
handle. For example, the following codeprints
on my system.
I like @nwellnhof's approach. Dealing only with Unicode and ASCII - a luxury few enjoy - my instinct would be to leave the bytes as is and selectively make use of
Encode
todecode()/encode()
when needed. If you are able to determine which of your data sources are problematic you could filter/insertdecode
when dealing with them.