2

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?

sid_com
  • 24,137
  • 26
  • 96
  • 187

1 Answers1

1

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
amon
  • 57,091
  • 2
  • 89
  • 149
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – James A Mohler Jan 30 '14 at 17:23
  • Quite the opposite, the copy I place here will become invalid if the linked page changes. All the more reason not to make a verbatim copy of the source. – ikegami Jan 30 '14 at 17:26
  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – Diosney Jan 30 '14 at 17:38
  • @diosney, Did you fail to notice the link? And I don't see anything unclear in the OP's question. If you need clarification, follow your own advice instead of leaving a comment telling me how. – ikegami Jan 30 '14 at 17:43
  • @ikegami, you know jolly well that overly short, or link-only answers are discouraged. Of course it's idiotic to just copy a few paragraphs from the linked source, but it makes it easier for the asker / future visitors to see how that link answers the question / solves their problems. I therefore edited in a relevant explanation. – amon Jan 30 '14 at 19:29
  • @amon, I know jolly well that overly short, or link-only answers are discouraged *when a better answer could be provided*. And then there's blatant plagiarism for no gain. – ikegami Jan 30 '14 at 19:32
  • @ikegami If my edit added no value, you're free to revert it. And a properly credited citation is neither “blatant plagiarism”, nor *necessary* (as my non-citing summary demonstrates). Anyway, thanks for *finding* that link, I learned something new about Perl today :-) – amon Jan 30 '14 at 19:45