# PerlIO::utf8_strict
📦 std
A UTF-8 I/O layer that refuses malformed input.
`:utf8_strict` decodes UTF-8 like `:encoding(UTF-8)`, much faster, and
like it unlike `:utf8` it validates: a read that meets an ill-formed
sequence, a surrogate, a non-shortest form, a code point beyond
U+10FFFF or a noncharacter dies. Writing through it encodes as
`:utf8` does.
## Synopsis
```perl
open my $fh, '<:utf8_strict', $file or die $!;
my $line = <$fh>; # dies on malformed UTF-8
open my $lax, '<:utf8_strict(allow_noncharacters)', $file or die $!;
binmode STDOUT, ':utf8_strict';
```
## Options
A comma-separated list in parentheses relaxes the check:
`allow_surrogates`, `allow_noncharacters`, `allow_nonshortest`, or
`loose` for all three; `strict`, the default, for none. An unknown
word dies with `Unknown argument to :utf8_strict`.
The errors are `Can't decode ill-formed UTF-8 octet sequence <..>`,
with the bytes in hex and `at end of file` when the input ends inside
a sequence, and `Can't interchange noncharacter code point U+..`. The
handle’s error flag is set as well.
This is a native implementation of PerlIO::utf8_strict 0.010’s
`utf8_strict.xs`; its `PerlIO/utf8_strict.pm` is used unchanged, and
perl loads it by itself the first time `:utf8_strict` is named.
## Differences from upstream
None.