Question

With Encode::encode there are different ways to handle malformed data.

Does for binmode like binmode STDOUT ":encoding( $encoding_out )" also exist possibilities to handle malformed data?

Was it helpful?

Solution

Yes, there's $PerlIO::encoding::fallback. You can assign the wanted “check” argument to that variable. When you then push a PerlIO layer onto a filehandle, the current value from that variable is saved for that layers failure behavior. E.g.:

use PerlIO::encoding;
use Encode;

# set a value
$PerlIO::encoding::fallback = Encode::FB_WARN;
# apply a layer under that value
open my $fh, '<:encoding(UTF-8)', $some_file or die ...;
# $PerlIO::encoding::fallback can be changed now
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top