locale
@x = sort @y; # ASCII sorting order
{
use locale;
@x = sort @y; # Locale–defined sorting order
}
@x = sort @y; # ASCII sorting order againThis lexically scoped pragma tells the compiler to enable (or
disable, under no locale) POSIX locales
for built-in operations. Enabling locales tells Perl’s string comparison
and case-related functionality to be respectful of your POSIX language environment. If this pragma is in
effect and your C library knows about POSIX locales, Perl looks to your
LC_CTYPE setting for regular
expressions and to your LC_COLLATE
setting for string comparisons like those in sort.
Since locales are more a form of nationalization than of internationalization, the use of locales may interact oddly with Unicode. It’s more portable and more reliable to use Perl’s native Unicode facilities for matters of casing and comparison, which are standard across all installations, instead of relying on possibly dodgy vendor locales. See the sections “Comparing and Sorting Unicode Text” and “Locale Sorting” in Chapter 6.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access