utf8::all(3pm)
π¦ NAME π¦
bestie. it's utf8::all (that's the manual page utf8::all(3pm), if we're being formal) and it's literally just: turn on Unicode β all of it. every last crumb. π
β¨ VERSION β¨
version 0.026 β keep up, she's been around. π
πΈ SYNOPSIS πΈ
use utf8::all; # Turn on UTF-8, all of it.
open my $in, '<', 'contains-utf8'; # UTF-8 already turned on here
print length 'fΓΈΓΈ bΔr'; # 7 UTF-8 characters
my $utf8_arg = shift @ARGV; # @ARGV is UTF-8 too (only for main)
π DESCRIPTION π
okay so first, the lore. the use utf8 pragma tells the Perl parser "hey girl, UTF-8 is allowed in the program text in the current lexical scope." which means you can finally use literal Unicode characters in your strings, your variable names, and your regular expressions like the main character you are. π«Ά
but utf8::all? she goes further:
charnamesget imported, so\N{...}sequences work and you can compile Unicode characters based on their names. iconic.- on Perl
v5.11.0or higher,use feature 'unicode_strings'is enabled. use feature fcanduse feature unicode_evalget enabled on Perl5.16.0and higher.- Filehandles are opened with UTF-8 encoding turned on by default β and yes bestie that includes
STDIN,STDOUT, andSTDERRwhenutf8::allis used from themainpackage. meaning they automatically convert UTF-8 octets to characters and vice versa. if you don't want UTF-8 for a particular filehandle, you'll have to setbinmode $filehandle. that's the deal. π @ARGVgets converted from UTF-8 octets to Unicode characters (whenutf8::allis used from themainpackage). this is similar to the behaviour of the-CAperl command-line switch (see perlrun). we love consistency. β¨readdir,readlink,readpipe(including theqx//and backtick operators), andglob(including the<>operator) now all work with and return Unicode characters instead of (UTF-8) octets β again, only whenutf8::allis used from themainpackage.
π Lexical Scope π
the pragma is lexically-scoped, so you can do the following if you had some reason to. no judgement, do what you want:
{
use utf8::all;
open my $out, '>', 'outfile';
my $utf8_str = 'fΓΈΓΈ bΔr';
print length $utf8_str, "\n"; # 7
print $out $utf8_str; # out as utf8
}
open my $in, '<', 'outfile'; # in as raw
my $text = do { local $/; <$in>};
print length $text, "\n"; # 10, not 7!
instead of doing the whole lexical scoping thing, you can also use no utf8::all to turn off the effects. easy.
β οΈ okay this one matters: note that the effect on@ARGVand theSTDIN,STDOUT, andSTDERRfile handles is always global and can not be undone! fr fr. no takebacks. π
π Enabling/Disabling Global Features π
as described above, the default behaviour of utf8::all is to convert @ARGV and to open the STDIN, STDOUT, and STDERR file handles with UTF-8 encoding, and override the readlink and readdir functions and glob operators when utf8::all is used from the main package.
if you want to disable these features even when utf8::all is used from the main package, add the option NO-GLOBAL (or LEXICAL-ONLY) to the use line. e.g.:
use utf8::all 'NO-GLOBAL';
if on the other hand you want to enable these global effects even when utf8::all was used from another package than main, use the option GLOBAL on the use line:
use utf8::all 'GLOBAL';
π UTF-8 Errors π
utf8::all will handle invalid code points (i.e., utf-8 that does not map to a valid unicode character) as a fatal error. she said no.
for glob, readdir, and readlink, one can change this behaviour by setting the attribute $utf8::all::UTF8_CHECK.
π ATTRIBUTES π
$utf8::all::UTF8_CHECK
by default utf8::all marks decoding errors as fatal (default value for this setting is Encode::FB_CROAK). if you want, you can change this by setting $utf8::all::UTF8_CHECK. the value Encode::FB_WARN reports the encoding errors as warnings, and Encode::FB_DEFAULT will completely ignore them. please see Encode for details. note: Encode::LEAVE_SRC is always enforced. always. periodt.
important: only controls the handling of decoding errors inglob,readdir, andreadlink. that's it. that's the scope.
π INTERACTION WITH AUTODIE π
if you use autodie β which is a great idea btw, chef's kiss β you need to use at least version 2.12, released on June 26, 2012: https://metacpan.org/source/PJF/autodie-2.12/Changes#L3. otherwise, autodie obliterates the IO layers set by the open pragma. π
see RT #54777 https://rt.cpan.org/Ticket/Display.html?id=54777 and GH #7 https://github.com/doherty/utf8-all/issues/7.
π BUGS π
please report any bugs or feature requests on the bugtracker website: https://github.com/doherty/utf8-all/issues.
when submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature. help her help you. π
π§ COMPATIBILITY π§
the filesystems of Dos, Windows, and OS/2 do not (fully) support UTF-8. the readlink and readdir functions and glob operators will therefore not be replaced on these systems. it's giving "we tried". πΈ
β SEE ALSO β
- File::Find::utf8 for fully utf-8 aware File::Find functions.
- Cwd::utf8 for fully utf-8 aware Cwd functions.
π AUTHORS π
- Michael Schwern
<mschwern@cpan.org> - Mike Doherty
<doherty@cpan.org> - Hayo Baan
<info@hayobaan.com>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2009 by Michael Schwern <mschwern@cpan.org>; he originated it. king behaviour. π
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page bestie, signed off from perl v5.40.1, dated 2026-01-18 β she ate and left no crumbs. bye slay π
β¨π¦
π¦ where this page comes from
- ubuntu resolute: libutf8-all-perl 0.026-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libutf8-all-perl 0.026-1 Β· Artistic-1.0-Perl OR 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