source::encoding(3perl) | Perl Programmers Reference Guide | source::encoding(3perl) |
NAME
source::encoding -- Declare Perl source code encoding
SYNOPSIS
use source::encoding 'ascii'; use source::encoding 'utf8'; no source::encoding;
DESCRIPTION
These days, Perl code either generally contains only ASCII characters with "\x{}" and similar escapes to represent non-ASCII, or "use utf8" is used to indicate that the source code itself contains characters encoded as UTF-8.
That means that a character in the source code not meeting these criteria is often a typographical error. This pragma is used to tell Perl to raise an error when this happens.
"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. The meaning of non-ASCII characters is then undefined.
"use source::encoding 'ascii'" is automatically enabled within the lexical scope of a "use v5.41.0" or higher.
SEE ALSO
utf8
2025-07-13 | perl v5.42.0 |