source::encoding(3pm)

πŸŽ€ NAME πŸŽ€

Okay bestie, this is source::encoding(3pm) from the Perl Programmers Reference Guide πŸ’– It’s literally called source::encoding β€” and its whole personality is declare Perl source code encoding. Periodt.

✨ SYNOPSIS ✨

use source::encoding 'ascii';
use source::encoding 'utf8';
no source::encoding;

🌸 DESCRIPTION 🌸

So these days, bestie, Perl code is usually doing one of two things: it’s generally only ASCII characters, with \x{} and similar escapes standing in for the non-ASCII bits, or it’s got use utf8 to say β€œhey, the source code itself contains characters encoded as UTF-8” ✨

That means when a character in the source code doesn’t meet those criteria, it’s often a typographical error πŸ‘€ This pragma is the one that tells Perl to raise an error when that happens. No silent weirdness, no cap.

  • use source::encoding 'utf8' is a synonym for use utf8 β€” they may be used interchangeably πŸ’…
  • use source::encoding 'ascii' turns off any UTF-8 expectations, and raises a fatal error if any character within its scope in the input source code is not ASCII (or ASCII-equivalent on EBCDIC systems) 🚨
  • no source::encoding turns off any UTF-8/ASCII expectations for the remainder of its scope. After that, the meaning of non-ASCII characters is undefined 😭 so don’t come crying to me if it gets feral.
  • use source::encoding 'ascii' is automatically enabled within the lexical scope of a use v5.41.0 or higher πŸ‘‘

πŸ¦‹ SEE ALSO πŸ¦‹

  • utf8 β€” that’s the whole vibe check 🫢

mwah πŸ’‹ β€” this page is source::encoding(3pm) from perl v5.42.3, dated 2026-11-03. Byeee πŸ’–

πŸ“¦ where this page comes from