=head1 NAME
-perllocale - Perl locale handling (internationlization and localization)
+perllocale - Perl locale handling (internationalization and localization)
=head1 DESCRIPTION
Perl can understand language-specific data via the standardized (ISO C,
XPG4, POSIX 1.c) method called "the locale system". The locale system is
-controlled per application using a pragma, one function call, and
+controlled per application using one pragma, one function call, and
several environment variables.
B<NOTE>: This feature is new in Perl 5.004, and does not apply unless an
application specifically requests it - see L<Backward compatibility>.
+The one exception is that write() now B<always> uses the current locale
+- see L<"NOTES">.
=head1 PREPARING TO USE LOCALES
C<LC_COLLATE>, C<LC_CTYPE>, and so on, are discussed further in L<LOCALE
CATEGORIES>.
-The default behaviour returns with S<C<no locale>> or on reaching the
+The default behavior returns with S<C<no locale>> or on reaching the
end of the enclosing block.
Note that the string result of any operation that uses locale
and see whether they list something resembling these
+ en_US.ISO8859-1 de_DE.ISO8859-1 ru_RU.ISO8859-5
+ en_US de_DE ru_RU
en de ru
- english de_DE russian
- english.iso88591 de_DE.ISO8859-1 russian.iso88595
- en_US german ru_RU
- en_US.ISO8859-1 german.iso88591 ru_RU.ISO8859-5
+ english german russian
+ english.iso88591 german.iso88591 russian.iso88595
Sadly, even though the calling interface for setlocale() has been
-standardized, the names of the locales have not. The form of the name
-is usually I<language_country>B</>I<territory>B<.>I<codeset>, but the
+standardized, the names of the locales and the directories where
+the configuration is, have not. The basic form of the name is
+I<language_country/territory>B<.>I<codeset>, but the
latter parts are not always present.
Two special locales are worth particular mention: "C" and "POSIX".
This machine-native collation (which is what you get unless S<C<use
locale>> has appeared earlier in the same block) must be used for
sorting raw binary data, whereas the locale-dependent collation of the
-first example is useful for written text.
+first example is useful for natural text.
As noted in L<USING LOCALES>, C<cmp> compares according to the current
collation locale when C<use locale> is in effect, but falls back to a
$equal_in_locale will be true if the collation locale specifies a
dictionary-like ordering which ignores space characters completely, and
-which folds case. Alternatively, you can use this idiom:
-
- use locale;
- $s_a = "space and case ignored";
- $s_b = "SpaceAndCaseIgnored";
- $equal_in_locale = $s_a ge $s_b && $s_a le $s_b;
-
-which works because neither C<ne> nor C<ge> falls back to doing a
-byte-by-byte comparison when the operands are equal according to the
-locale. The idiom may be less efficient than using strcoll(), but,
-unlike that function, it is not confused by strings containing embedded
-nulls.
+which folds case.
If you have a single string which you want to check for "equality in
locale" against several others, you might think you could gain a little
magic (see L<perlguts/Magic>) creates the transformed version of a
string the first time it's needed in a comparison, then keeps it around
in case it's needed again. An example rewritten the easy way with
-C<cmp> runs just about as fast. It also copes with null characters
+C<cmp> runs just about as fast. It also copes with null characters
embedded in strings; if you call strxfrm() directly, it treats the first
-null it finds as a terminator. In short, don't call strxfrm() directly:
-let Perl do it for you.
+null it finds as a terminator. And don't expect the transformed strings
+it produces to be portable across systems - or even from one revision
+of your operating system to the next. In short, don't call strxfrm()
+directly: let Perl do it for you.
Note: C<use locale> isn't shown in some of these examples, as it isn't
needed: strcoll() and strxfrm() exist only to generate locale-dependent
setting, characters like 'E<aelig>', 'E<eth>', 'E<szlig>', and
'E<oslash>' may be understood as C<\w> characters.
-C<LC_CTYPE> also affects the POSIX character-class test functions -
+The C<LC_CTYPE> locale also provides the map used in translating
+characters between lower- and upper-case. This affects the case-mapping
+functions - lc(), lcfirst, uc() and ucfirst(); case-mapping
+interpolation with C<\l>, C<\L>, C<\u> or <\U> in double-quoted strings
+and in C<s///> substitutions; and case-independent regular expression
+pattern matching using the C<i> modifier.
+
+Finally, C<LC_CTYPE> affects the POSIX character-class test functions -
isalpha(), islower() and so on. For example, if you move from the "C"
locale to a 7-bit Scandinavian one, you may find - possibly to your
surprise - that "|" moves from the ispunct() class to isalpha().
The C standard defines the C<LC_MONETARY> category, but no function that
is affected by its contents. (Those with experience of standards
-committees will recognise that the working group decided to punt on the
+committees will recognize that the working group decided to punt on the
issue.) Consequently, Perl takes no notice of it. If you really want
to use C<LC_MONETARY>, you can query its contents - see L<The localeconv
function> - and use the information that it returns in your
-application's own formating of currency amounts. However, you may well
+application's own formatting of currency amounts. However, you may well
find that the information, though voluminous and complex, does not quite
meet your requirements: currency formatting is a hard nut to crack.
The remaining locale category, C<LC_MESSAGES> (possibly supplemented by
others in particular implementations) is not currently used by Perl -
-except possibly to affect the behaviour of library functions called by
+except possibly to affect the behavior of library functions called by
extensions which are not part of the standard Perl distribution.
=head1 SECURITY
=item *
+String interpolation with case-mapping, as in, say, C<$dest =
+"C:\U$name.$ext">, may produce dangerous results if a bogus LC_CTYPE
+case-mapping table is in effect.
+
+=item *
+
If the decimal point character in the C<LC_NUMERIC> locale is
surreptitiously changed from a dot to a comma, C<sprintf("%g",
0.123456e3)> produces a string result of "123,456". Many people would
C<use locale> is in effect, Perl uses the tainting mechanism (see
L<perlsec>) to mark string results which become locale-dependent, and
which may be untrustworthy in consequence. Here is a summary of the
-tainting behaviour of operators and functions which may be affected by
+tainting behavior of operators and functions which may be affected by
the locale:
=over 4
Scalar true/false (or less/equal/greater) result is never tainted.
+=item B<Case-mapping interpolation> (with C<\l>, C<\L>, C<\u> or <\U>)
+
+Result string containing interpolated material is tainted if
+C<use locale> is in effect.
+
=item B<Matching operator> (C<m//>):
Scalar true/false result never tainted.
Subpatterns, either delivered as an array-context result, or as $1 etc.
are tainted if C<use locale> is in effect, and the subpattern regular
-expression contains C<\w> (to match an alphanumeric character). The
-matched pattern variable, $&, is also tainted if C<use locale> is in
-effect, and the regular expression contains C<\w>.
+expression contains C<\w> (to match an alphanumeric character), C<\W>
+(non-alphanumeric character), C<\s> (white-space character), or C<\S>
+(non white-space character). The matched pattern variable, $&, $`
+(pre-match), $' (post-match), and $+ (last match) are also tainted if
+C<use locale> is in effect and the regular expression contains C<\w>,
+C<\W>, C<\s>, or C<\S>.
=item B<Substitution operator> (C<s///>):
-Has the same behaviour as the match operator. When C<use locale> is
-in effect, he left operand of C<=~> will become tainted if it is
-modified as a result of a substitution based on a regular expression
-match involving C<\w>.
+Has the same behavior as the match operator. Also, the left
+operand of C<=~> becomes tainted when C<use locale> in effect,
+if it is modified as a result of a substitution based on a regular
+expression match involving C<\w>, C<\W>, C<\s>, or C<\S>; or of
+case-mapping with C<\l>, C<\L>,C<\u> or <\U>.
=item B<In-memory formatting function> (sprintf()):
=head2 Backward compatibility
-Versions of Perl prior to 5.004 ignored locale information, generally
-behaving as if something similar to the C<"C"> locale (see L<The
-setlocale function>) was always in force, even if the program
+Versions of Perl prior to 5.004 B<mostly> ignored locale information,
+generally behaving as if something similar to the C<"C"> locale (see
+L<The setlocale function>) was always in force, even if the program
environment suggested otherwise. By default, Perl still behaves this
way so as to maintain backward compatibility. If you want a Perl
-application to pay attention to locale information, you B<must> use the
-S<C<use locale>> pragma (see L<The S<C<use locale>> Pragma>) to instruct
-it to do so.
+application to pay attention to locale information, you B<must> use
+the S<C<use locale>> pragma (see L<The S<C<use locale>> Pragma>) to
+instruct it to do so.
+
+Versions of Perl from 5.002 to 5.003 did use the C<LC_CTYPE>
+information if that was available, that is, C<\w> did understand what
+are the letters according to the locale environment variables.
+The problem was that the user had no control over the feature:
+if the C library supported locales, Perl used them.
+
+=head2 I18N:Collate obsolete
+
+In versions of Perl prior to 5.004 per-locale collation was possible
+using the C<I18N::Collate> library module. This module is now mildly
+obsolete and should be avoided in new applications. The C<LC_COLLATE>
+functionality is now integrated into the Perl core language: One can
+use locale-specific scalar data completely normally with C<use locale>,
+so there is no longer any need to juggle with the scalar references of
+C<I18N::Collate>.
=head2 Sort speed and memory use impacts
and the locale.) These downsides are dictated more by the operating
system's implementation of the locale system than by Perl.
-=head2 I18N:Collate
+=head2 write() and LC_NUMERIC
-In Perl 5.003 (and later development releases prior to 5.003_06),
-per-locale collation was possible using the C<I18N::Collate> library
-module. This is now mildly obsolete and should be avoided in new
-applications. The C<LC_COLLATE> functionality is now integrated into
-the Perl core language and one can use locale-specific scalar data
-completely normally - there is no need to juggle with the scalar
-references of C<I18N::Collate>.
+Formats are the only part of Perl which unconditionally use information
+from a program's locale; if a program's environment specifies an
+LC_NUMERIC locale, it is always used to specify the decimal point
+character in formatted output. Formatted output cannot be controlled by
+C<use locale> because the pragma is tied to the block structure of the
+program, and, for historical reasons, formats exist outside that block
+structure.
=head2 Freely available locale definitions
=head2 I18n and l10n
-Internationalization is often abbreviated as B<i18n> because its first
-and last letters are separated by eighteen others. In the same way, you
-abbreviate localization to B<l10n>.
+"Internationalization" is often abbreviated as B<i18n> because its first
+and last letters are separated by eighteen others. (You may guess why
+the internalin ... internaliti ... i18n tends to get abbreviated.) In
+the same way, "localization" is often abbreviated to B<l10n>.
=head2 An imperfect standard
=head2 Broken systems
-In certain system environments the operating system's locale support is
-broken and cannot be fixed or used by Perl. Such deficiencies can and
-will result in mysterious hangs and/or Perl core dumps. One example is
-IRIX before release 6.2, in which the C<LC_COLLATE> support simply does
-not work. When confronted with such a system, please report in
-excruciating detail to C<perlbug@perl.com>, and complain to your vendor:
-maybe some bug fixes exist for these problems in your operating system.
-Sometimes such bug fixes are called an operating system upgrade.
+In certain system environments the operating system's locale support
+is broken and cannot be fixed or used by Perl. Such deficiencies can
+and will result in mysterious hangs and/or Perl core dumps when the
+C<use locale> is in effect. When confronted with such a system,
+please report in excruciating detail to C<perlbug@perl.com>, and
+complain to your vendor: maybe some bug fixes exist for these problems
+in your operating system. Sometimes such bug fixes are called an
+operating system upgrade.
=head1 SEE ALSO
=head1 HISTORY
-Jarrko Hietaniemi's original F<perli18n.pod> heavily hacked by Dominic
+Jarkko Hietaniemi's original F<perli18n.pod> heavily hacked by Dominic
Dunlop, assisted by the perl5-porters.
-Last update: Mon Dec 23 10:44:08 EST 1996
+Last update: Wed Jan 22 11:04:58 EST 1997