home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Book Home Programming PerlSearch this book

31.14. use locale

@x = sort @y;       # ASCII sorting order
{
    use locale;
    @x = sort @y;   # Locale-defined sorting order
}
@x = sort @y;       # ASCII sorting order again

This lexically scoped pragma tells the compiler to enable (or disable, under no locale) the use of POSIX locales for built-in operations. Enabling locales tells Perl's case-conversion functions and pattern-matching engine to be respectful of your language environment, allowing for characters with diacritical markings, etc. 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. See Chapter 15, "Unicode" for more on internationalization.



Library Navigation Links

Copyright © 2001 O'Reilly & Associates. All rights reserved.