PERLIO::ENCODING(3perl)
β¨ PerlIO::encoding π
okay bestie, welcome to the PerlIO::encoding page from the Perl Programmers Reference Guide π«Ά β this is the lil corner of the manual that teaches your filehandles how to speak other languages. literally. no cap.
πΈ NAME πΈ
PerlIO::encoding β it's the encoding layer, periodt. that's the whole name, iconic and to the point π
π SYNOPSIS π
here's the vibe, copy it exactly bestie:
use PerlIO::encoding;
open($f, "<:encoding(foo)", "infoo");
open($f, ">:encoding(bar)", "outbar");
use Encode qw(:fallbacks);
$PerlIO::encoding::fallback = FB_PERLQQ;
like. look at her. opening files with an encoding filter just built in to the mode string. main character energy fr fr β¨
π DESCRIPTION π
so what's actually happening?? this PerlIO layer opens a filehandle with a transparent encoding filter β¨ β transparent meaning you don't even have to think about it, it just does the thing behind the scenes while you live your life π¦
On input, it takes the bytes that are expected to be in the character set and encoding you specified, and converts them into Perl string data (that's Unicode, and Perl's internal Unicode encoding, UTF-8 π). so like, bytes go in, actual Perl strings come out.
On output, it does the reverse glow-up β it converts Perl string data into the character set and encoding you asked for π . strings go in, correctly-encoded bytes come out.
and here's the detail you CANNOT skip, bestie π: when the layer gets pushed, the current value of $PerlIO::encoding::fallback is saved, and that saved value gets used as the CHECK argument when it calls the Encode methods encode() and decode(). so if you're setting that variable, set it before the layer gets pushed, iykyk π
π₯ SEE ALSO π₯
openEncode"binmode" in perlfuncperluniintro
go read those too, they're all part of the same friend group π
okay that's the whole page babe, you ate it π
slay β this was perl v5.44.0, dated 2026-10-17, and that's your PerlIO::encoding(3perl) page, signing off ππβ¨
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms