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 πŸ”₯

  • open
  • Encode
  • "binmode" in perlfunc
  • perluniintro

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