Install Perl 5.8.8
[msysgit.git] / mingw / html / pod / perllocale.html
blobea2731c09ee613cb6fa49d2ab1d1f65675126190
1 <?xml version="1.0" ?>
2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml">
4 <head>
5 <title>perllocale - Perl locale handling</title>
6 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
7 <link rev="made" href="mailto:" />
8 </head>
10 <body style="background-color: white">
11 <table border="0" width="100%" cellspacing="0" cellpadding="3">
12 <tr><td class="block" style="background-color: #cccccc" valign="middle">
13 <big><strong><span class="block">&nbsp;perllocale - Perl locale handling</span></strong></big>
14 </td></tr>
15 </table>
17 <p><a name="__index__"></a></p>
18 <!-- INDEX BEGIN -->
20 <ul>
22 <li><a href="#name">NAME</a></li>
23 <li><a href="#description">DESCRIPTION</a></li>
24 <li><a href="#preparing_to_use_locales">PREPARING TO USE LOCALES</a></li>
25 <li><a href="#using_locales">USING LOCALES</a></li>
26 <ul>
28 <li><a href="#the_use_locale_pragma">The use locale pragma</a></li>
29 <li><a href="#the_setlocale_function">The setlocale function</a></li>
30 <li><a href="#finding_locales">Finding locales</a></li>
31 <li><a href="#locale_problems">LOCALE PROBLEMS</a></li>
32 <li><a href="#temporarily_fixing_locale_problems">Temporarily fixing locale problems</a></li>
33 <li><a href="#permanently_fixing_locale_problems">Permanently fixing locale problems</a></li>
34 <li><a href="#permanently_fixing_your_system_s_locale_configuration">Permanently fixing your system's locale configuration</a></li>
35 <li><a href="#fixing_system_locale_configuration">Fixing system locale configuration</a></li>
36 <li><a href="#the_localeconv_function">The localeconv function</a></li>
37 <li><a href="#i18n__langinfo">I18N::Langinfo</a></li>
38 </ul>
40 <li><a href="#locale_categories">LOCALE CATEGORIES</a></li>
41 <ul>
43 <li><a href="#category_lc_collate__collation">Category LC_COLLATE: Collation</a></li>
44 <li><a href="#category_lc_ctype__character_types">Category LC_CTYPE: Character Types</a></li>
45 <li><a href="#category_lc_numeric__numeric_formatting">Category LC_NUMERIC: Numeric Formatting</a></li>
46 <li><a href="#category_lc_monetary__formatting_of_monetary_amounts">Category LC_MONETARY: Formatting of monetary amounts</a></li>
47 <li><a href="#lc_time">LC_TIME</a></li>
48 <li><a href="#other_categories">Other categories</a></li>
49 </ul>
51 <li><a href="#security">SECURITY</a></li>
52 <li><a href="#environment">ENVIRONMENT</a></li>
53 <li><a href="#notes">NOTES</a></li>
54 <ul>
56 <li><a href="#backward_compatibility">Backward compatibility</a></li>
57 <li><a href="#i18n_collate_obsolete">I18N:Collate obsolete</a></li>
58 <li><a href="#sort_speed_and_memory_use_impacts">Sort speed and memory use impacts</a></li>
59 <li><a href="#write___and_lc_numeric"><a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_write"><code>write()</code></a> and LC_NUMERIC</a></li>
60 <li><a href="#freely_available_locale_definitions">Freely available locale definitions</a></li>
61 <li><a href="#i18n_and_l10n">I18n and l10n</a></li>
62 <li><a href="#an_imperfect_standard">An imperfect standard</a></li>
63 </ul>
65 <li><a href="#unicode_and_utf8">Unicode and UTF-8</a></li>
66 <li><a href="#bugs">BUGS</a></li>
67 <ul>
69 <li><a href="#broken_systems">Broken systems</a></li>
70 </ul>
72 <li><a href="#see_also">SEE ALSO</a></li>
73 <li><a href="#history">HISTORY</a></li>
74 </ul>
75 <!-- INDEX END -->
77 <hr />
78 <p>
79 </p>
80 <h1><a name="name">NAME</a></h1>
81 <p>perllocale - Perl locale handling (internationalization and localization)</p>
82 <p>
83 </p>
84 <hr />
85 <h1><a name="description">DESCRIPTION</a></h1>
86 <p>Perl supports language-specific notions of data such as ``is this
87 a letter'', ``what is the uppercase equivalent of this letter'', and
88 ``which of these letters comes first''. These are important issues,
89 especially for languages other than English--but also for English: it
90 would be na&iuml;ve to imagine that <code>A-Za-z</code> defines all the ``letters''
91 needed to write in English. Perl is also aware that some character other
92 than '.' may be preferred as a decimal point, and that output date
93 representations may be language-specific. The process of making an
94 application take account of its users' preferences in such matters is
95 called <strong>internationalization</strong> (often abbreviated as <strong>i18n</strong>); telling
96 such an application about a particular set of preferences is known as
97 <strong>localization</strong> (<strong>l10n</strong>).</p>
98 <p>Perl can understand language-specific data via the standardized (ISO C,
99 XPG4, POSIX 1.c) method called ``the locale system''. The locale system is
100 controlled per application using one pragma, one function call, and
101 several environment variables.</p>
102 <p><strong>NOTE</strong>: This feature is new in Perl 5.004, and does not apply unless an
103 application specifically requests it--see <a href="#backward_compatibility">Backward compatibility</a>.
104 The one exception is that <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_write"><code>write()</code></a> now <strong>always</strong> uses the current locale
105 - see <a href="#notes">NOTES</a>.</p>
107 </p>
108 <hr />
109 <h1><a name="preparing_to_use_locales">PREPARING TO USE LOCALES</a></h1>
110 <p>If Perl applications are to understand and present your data
111 correctly according a locale of your choice, <strong>all</strong> of the following
112 must be true:</p>
113 <ul>
114 <li>
115 <p><strong>Your operating system must support the locale system</strong>. If it does,
116 you should find that the <code>setlocale()</code> function is a documented part of
117 its C library.</p>
118 </li>
119 <li>
120 <p><strong>Definitions for locales that you use must be installed</strong>. You, or
121 your system administrator, must make sure that this is the case. The
122 available locales, the location in which they are kept, and the manner
123 in which they are installed all vary from system to system. Some systems
124 provide only a few, hard-wired locales and do not allow more to be
125 added. Others allow you to add ``canned'' locales provided by the system
126 supplier. Still others allow you or the system administrator to define
127 and add arbitrary locales. (You may have to ask your supplier to
128 provide canned locales that are not delivered with your operating
129 system.) Read your system documentation for further illumination.</p>
130 </li>
131 <li>
132 <p><strong>Perl must believe that the locale system is supported</strong>. If it does,
133 <code>perl -V:d_setlocale</code> will say that the value for <code>d_setlocale</code> is
134 <code>define</code>.</p>
135 </li>
136 </ul>
137 <p>If you want a Perl application to process and present your data
138 according to a particular locale, the application code should include
139 the <code>use&nbsp;locale</code> pragma (see <a href="#the_use_locale_pragma">The use locale pragma</a>) where
140 appropriate, and <strong>at least one</strong> of the following must be true:</p>
141 <ul>
142 <li>
143 <p><strong>The locale-determining environment variables (see <a href="#environment">ENVIRONMENT</a>)
144 must be correctly set up</strong> at the time the application is started, either
145 by yourself or by whoever set up your system account.</p>
146 </li>
147 <li>
148 <p><strong>The application must set its own locale</strong> using the method described in
149 <a href="#the_setlocale_function">The setlocale function</a>.</p>
150 </li>
151 </ul>
153 </p>
154 <hr />
155 <h1><a name="using_locales">USING LOCALES</a></h1>
157 </p>
158 <h2><a name="the_use_locale_pragma">The use locale pragma</a></h2>
159 <p>By default, Perl ignores the current locale. The <code>use&nbsp;locale</code>
160 pragma tells Perl to use the current locale for some operations:</p>
161 <ul>
162 <li>
163 <p><strong>The comparison operators</strong> (<code>lt</code>, <code>le</code>, <code>cmp</code>, <code>ge</code>, and <code>gt</code>) and
164 the POSIX string collation functions <code>strcoll()</code> and <code>strxfrm()</code> use
165 <a href="#item_lc_collate"><code>LC_COLLATE</code></a>. <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_sort"><code>sort()</code></a> is also affected if used without an
166 explicit comparison function, because it uses <code>cmp</code> by default.</p>
167 <p><strong>Note:</strong> <code>eq</code> and <code>ne</code> are unaffected by locale: they always
168 perform a char-by-char comparison of their scalar operands. What's
169 more, if <code>cmp</code> finds that its operands are equal according to the
170 collation sequence specified by the current locale, it goes on to
171 perform a char-by-char comparison, and only returns <em>0</em> (equal) if the
172 operands are char-for-char identical. If you really want to know whether
173 two strings--which <code>eq</code> and <code>cmp</code> may consider different--are equal
174 as far as collation in the locale is concerned, see the discussion in
175 <a href="#category_lc_collate__collation">Category LC_COLLATE: Collation</a>.</p>
176 </li>
177 <li>
178 <p><strong>Regular expressions and case-modification functions</strong> (uc(), lc(),
179 ucfirst(), and <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_lcfirst"><code>lcfirst())</code></a> use <a href="#item_lc_ctype"><code>LC_CTYPE</code></a></p>
180 </li>
181 <li>
182 <p><strong>The formatting functions</strong> (printf(), <code>sprintf()</code> and <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_write"><code>write())</code></a> use
183 <a href="#item_lc_numeric"><code>LC_NUMERIC</code></a></p>
184 </li>
185 <li>
186 <p><strong>The POSIX date formatting function</strong> (strftime()) uses <a href="#item_lc_time"><code>LC_TIME</code></a>.</p>
187 </li>
188 </ul>
189 <p><a href="#item_lc_collate"><code>LC_COLLATE</code></a>, <a href="#item_lc_ctype"><code>LC_CTYPE</code></a>, and so on, are discussed further in
190 <a href="#locale_categories">LOCALE CATEGORIES</a>.</p>
191 <p>The default behavior is restored with the <code>no&nbsp;locale</code> pragma, or
192 upon reaching the end of block enclosing <code>use locale</code>.</p>
193 <p>The string result of any operation that uses locale
194 information is tainted, as it is possible for a locale to be
195 untrustworthy. See <a href="#security">SECURITY</a>.</p>
197 </p>
198 <h2><a name="the_setlocale_function">The setlocale function</a></h2>
199 <p>You can switch locales as often as you wish at run time with the
200 POSIX::setlocale() function:</p>
201 <pre>
202 # This functionality not usable prior to Perl 5.004
203 require 5.004;</pre>
204 <pre>
205 # Import locale-handling tool set from POSIX module.
206 # This example uses: setlocale -- the function call
207 # LC_CTYPE -- explained below
208 use POSIX qw(locale_h);</pre>
209 <pre>
210 # query and save the old locale
211 $old_locale = setlocale(LC_CTYPE);</pre>
212 <pre>
213 setlocale(LC_CTYPE, &quot;fr_CA.ISO8859-1&quot;);
214 # LC_CTYPE now in locale &quot;French, Canada, codeset ISO 8859-1&quot;</pre>
215 <pre>
216 setlocale(LC_CTYPE, &quot;&quot;);
217 # LC_CTYPE now reset to default defined by LC_ALL/LC_CTYPE/LANG
218 # environment variables. See below for documentation.</pre>
219 <pre>
220 # restore the old locale
221 setlocale(LC_CTYPE, $old_locale);</pre>
222 <p>The first argument of <code>setlocale()</code> gives the <strong>category</strong>, the second the
223 <strong>locale</strong>. The category tells in what aspect of data processing you
224 want to apply locale-specific rules. Category names are discussed in
225 <a href="#locale_categories">LOCALE CATEGORIES</a> and <a href="#environment">ENVIRONMENT</a>. The locale is the name of a
226 collection of customization information corresponding to a particular
227 combination of language, country or territory, and codeset. Read on for
228 hints on the naming of locales: not all systems name locales as in the
229 example.</p>
230 <p>If no second argument is provided and the category is something else
231 than LC_ALL, the function returns a string naming the current locale
232 for the category. You can use this value as the second argument in a
233 subsequent call to setlocale().</p>
234 <p>If no second argument is provided and the category is LC_ALL, the
235 result is implementation-dependent. It may be a string of
236 concatenated locales names (separator also implementation-dependent)
237 or a single locale name. Please consult your <em>setlocale(3)</em> for
238 details.</p>
239 <p>If a second argument is given and it corresponds to a valid locale,
240 the locale for the category is set to that value, and the function
241 returns the now-current locale value. You can then use this in yet
242 another call to setlocale(). (In some implementations, the return
243 value may sometimes differ from the value you gave as the second
244 argument--think of it as an alias for the value you gave.)</p>
245 <p>As the example shows, if the second argument is an empty string, the
246 category's locale is returned to the default specified by the
247 corresponding environment variables. Generally, this results in a
248 return to the default that was in force when Perl started up: changes
249 to the environment made by the application after startup may or may not
250 be noticed, depending on your system's C library.</p>
251 <p>If the second argument does not correspond to a valid locale, the locale
252 for the category is not changed, and the function returns <em>undef</em>.</p>
253 <p>For further information about the categories, consult <em>setlocale(3)</em>.</p>
255 </p>
256 <h2><a name="finding_locales">Finding locales</a></h2>
257 <p>For locales available in your system, consult also <em>setlocale(3)</em> to
258 see whether it leads to the list of available locales (search for the
259 <em>SEE ALSO</em> section). If that fails, try the following command lines:</p>
260 <pre>
261 locale -a</pre>
262 <pre>
263 nlsinfo</pre>
264 <pre>
265 ls /usr/lib/nls/loc</pre>
266 <pre>
267 ls /usr/lib/locale</pre>
268 <pre>
269 ls /usr/lib/nls</pre>
270 <pre>
271 ls /usr/share/locale</pre>
272 <p>and see whether they list something resembling these</p>
273 <pre>
274 en_US.ISO8859-1 de_DE.ISO8859-1 ru_RU.ISO8859-5
275 en_US.iso88591 de_DE.iso88591 ru_RU.iso88595
276 en_US de_DE ru_RU
277 en de ru
278 english german russian
279 english.iso88591 german.iso88591 russian.iso88595
280 english.roman8 russian.koi8r</pre>
281 <p>Sadly, even though the calling interface for <code>setlocale()</code> has been
282 standardized, names of locales and the directories where the
283 configuration resides have not been. The basic form of the name is
284 <em>language_territory</em><strong>.</strong><em>codeset</em>, but the latter parts after
285 <em>language</em> are not always present. The <em>language</em> and <em>country</em>
286 are usually from the standards <strong>ISO 3166</strong> and <strong>ISO 639</strong>, the
287 two-letter abbreviations for the countries and the languages of the
288 world, respectively. The <em>codeset</em> part often mentions some <strong>ISO
289 8859</strong> character set, the Latin codesets. For example, <code>ISO 8859-1</code>
290 is the so-called ``Western European codeset'' that can be used to encode
291 most Western European languages adequately. Again, there are several
292 ways to write even the name of that one standard. Lamentably.</p>
293 <p>Two special locales are worth particular mention: ``C'' and ``POSIX''.
294 Currently these are effectively the same locale: the difference is
295 mainly that the first one is defined by the C standard, the second by
296 the POSIX standard. They define the <strong>default locale</strong> in which
297 every program starts in the absence of locale information in its
298 environment. (The <em>default</em> default locale, if you will.) Its language
299 is (American) English and its character codeset ASCII.</p>
300 <p><strong>NOTE</strong>: Not all systems have the ``POSIX'' locale (not all systems are
301 POSIX-conformant), so use ``C'' when you need explicitly to specify this
302 default locale.</p>
304 </p>
305 <h2><a name="locale_problems">LOCALE PROBLEMS</a></h2>
306 <p>You may encounter the following warning message at Perl startup:</p>
307 <pre>
308 perl: warning: Setting locale failed.
309 perl: warning: Please check that your locale settings:
310 LC_ALL = &quot;En_US&quot;,
311 LANG = (unset)
312 are supported and installed on your system.
313 perl: warning: Falling back to the standard locale (&quot;C&quot;).</pre>
314 <p>This means that your locale settings had LC_ALL set to ``En_US'' and
315 LANG exists but has no value. Perl tried to believe you but could not.
316 Instead, Perl gave up and fell back to the ``C'' locale, the default locale
317 that is supposed to work no matter what. This usually means your locale
318 settings were wrong, they mention locales your system has never heard
319 of, or the locale installation in your system has problems (for example,
320 some system files are broken or missing). There are quick and temporary
321 fixes to these problems, as well as more thorough and lasting fixes.</p>
323 </p>
324 <h2><a name="temporarily_fixing_locale_problems">Temporarily fixing locale problems</a></h2>
325 <p>The two quickest fixes are either to render Perl silent about any
326 locale inconsistencies or to run Perl under the default locale ``C''.</p>
327 <p>Perl's moaning about locale problems can be silenced by setting the
328 environment variable PERL_BADLANG to a zero value, for example ``0''.
329 This method really just sweeps the problem under the carpet: you tell
330 Perl to shut up even when Perl sees that something is wrong. Do not
331 be surprised if later something locale-dependent misbehaves.</p>
332 <p>Perl can be run under the ``C'' locale by setting the environment
333 variable LC_ALL to ``C''. This method is perhaps a bit more civilized
334 than the PERL_BADLANG approach, but setting LC_ALL (or
335 other locale variables) may affect other programs as well, not just
336 Perl. In particular, external programs run from within Perl will see
337 these changes. If you make the new settings permanent (read on), all
338 programs you run see the changes. See <em>ENVIRONMENT</em> for
339 the full list of relevant environment variables and <a href="#using_locales">USING LOCALES</a>
340 for their effects in Perl. Effects in other programs are
341 easily deducible. For example, the variable LC_COLLATE may well affect
342 your <strong>sort</strong> program (or whatever the program that arranges ``records''
343 alphabetically in your system is called).</p>
344 <p>You can test out changing these variables temporarily, and if the
345 new settings seem to help, put those settings into your shell startup
346 files. Consult your local documentation for the exact details. For in
347 Bourne-like shells (<strong>sh</strong>, <strong>ksh</strong>, <strong>bash</strong>, <strong>zsh</strong>):</p>
348 <pre>
349 LC_ALL=en_US.ISO8859-1
350 export LC_ALL</pre>
351 <p>This assumes that we saw the locale ``en_US.ISO8859-1'' using the commands
352 discussed above. We decided to try that instead of the above faulty
353 locale ``En_US''--and in Cshish shells (<strong>csh</strong>, <strong>tcsh</strong>)</p>
354 <pre>
355 setenv LC_ALL en_US.ISO8859-1</pre>
356 <p>or if you have the ``env'' application you can do in any shell</p>
357 <pre>
358 env LC_ALL=en_US.ISO8859-1 perl ...</pre>
359 <p>If you do not know what shell you have, consult your local
360 helpdesk or the equivalent.</p>
362 </p>
363 <h2><a name="permanently_fixing_locale_problems">Permanently fixing locale problems</a></h2>
364 <p>The slower but superior fixes are when you may be able to yourself
365 fix the misconfiguration of your own environment variables. The
366 mis(sing)configuration of the whole system's locales usually requires
367 the help of your friendly system administrator.</p>
368 <p>First, see earlier in this document about <a href="#finding_locales">Finding locales</a>. That tells
369 how to find which locales are really supported--and more importantly,
370 installed--on your system. In our example error message, environment
371 variables affecting the locale are listed in the order of decreasing
372 importance (and unset variables do not matter). Therefore, having
373 LC_ALL set to ``En_US'' must have been the bad choice, as shown by the
374 error message. First try fixing locale settings listed first.</p>
375 <p>Second, if using the listed commands you see something <strong>exactly</strong>
376 (prefix matches do not count and case usually counts) like ``En_US''
377 without the quotes, then you should be okay because you are using a
378 locale name that should be installed and available in your system.
379 In this case, see <a href="#permanently_fixing_your_system_s_locale_configuration">Permanently fixing your system's locale configuration</a>.</p>
381 </p>
382 <h2><a name="permanently_fixing_your_system_s_locale_configuration">Permanently fixing your system's locale configuration</a></h2>
383 <p>This is when you see something like:</p>
384 <pre>
385 perl: warning: Please check that your locale settings:
386 LC_ALL = &quot;En_US&quot;,
387 LANG = (unset)
388 are supported and installed on your system.</pre>
389 <p>but then cannot see that ``En_US'' listed by the above-mentioned
390 commands. You may see things like ``en_US.ISO8859-1'', but that isn't
391 the same. In this case, try running under a locale
392 that you can list and which somehow matches what you tried. The
393 rules for matching locale names are a bit vague because
394 standardization is weak in this area. See again the
395 <a href="#finding_locales">Finding locales</a> about general rules.</p>
397 </p>
398 <h2><a name="fixing_system_locale_configuration">Fixing system locale configuration</a></h2>
399 <p>Contact a system administrator (preferably your own) and report the exact
400 error message you get, and ask them to read this same documentation you
401 are now reading. They should be able to check whether there is something
402 wrong with the locale configuration of the system. The <a href="#finding_locales">Finding locales</a>
403 section is unfortunately a bit vague about the exact commands and places
404 because these things are not that standardized.</p>
406 </p>
407 <h2><a name="the_localeconv_function">The localeconv function</a></h2>
408 <p>The POSIX::localeconv() function allows you to get particulars of the
409 locale-dependent numeric formatting information specified by the current
410 <a href="#item_lc_numeric"><code>LC_NUMERIC</code></a> and <a href="#item_lc_monetary"><code>LC_MONETARY</code></a> locales. (If you just want the name of
411 the current locale for a particular category, use POSIX::setlocale()
412 with a single parameter--see <a href="#the_setlocale_function">The setlocale function</a>.)</p>
413 <pre>
414 use POSIX qw(locale_h);</pre>
415 <pre>
416 # Get a reference to a hash of locale-dependent info
417 $locale_values = localeconv();</pre>
418 <pre>
419 # Output sorted list of the values
420 for (sort keys %$locale_values) {
421 printf &quot;%-20s = %s\n&quot;, $_, $locale_values-&gt;{$_}
422 }</pre>
423 <p><code>localeconv()</code> takes no arguments, and returns <strong>a reference to</strong> a hash.
424 The keys of this hash are variable names for formatting, such as
425 <code>decimal_point</code> and <code>thousands_sep</code>. The values are the
426 corresponding, er, values. See <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/localeconv.html">localeconv in the POSIX manpage</a> for a longer
427 example listing the categories an implementation might be expected to
428 provide; some provide more and others fewer. You don't need an
429 explicit <code>use locale</code>, because <code>localeconv()</code> always observes the
430 current locale.</p>
431 <p>Here's a simple-minded example program that rewrites its command-line
432 parameters as integers correctly formatted in the current locale:</p>
433 <pre>
434 # See comments in previous example
435 require 5.004;
436 use POSIX qw(locale_h);</pre>
437 <pre>
438 # Get some of locale's numeric formatting parameters
439 my ($thousands_sep, $grouping) =
440 @{localeconv()}{'thousands_sep', 'grouping'};</pre>
441 <pre>
442 # Apply defaults if values are missing
443 $thousands_sep = ',' unless $thousands_sep;</pre>
444 <pre>
445 # grouping and mon_grouping are packed lists
446 # of small integers (characters) telling the
447 # grouping (thousand_seps and mon_thousand_seps
448 # being the group dividers) of numbers and
449 # monetary quantities. The integers' meanings:
450 # 255 means no more grouping, 0 means repeat
451 # the previous grouping, 1-254 means use that
452 # as the current grouping. Grouping goes from
453 # right to left (low to high digits). In the
454 # below we cheat slightly by never using anything
455 # else than the first grouping (whatever that is).
456 if ($grouping) {
457 @grouping = unpack(&quot;C*&quot;, $grouping);
458 } else {
459 @grouping = (3);
460 }</pre>
461 <pre>
462 # Format command line params for current locale
463 for (@ARGV) {
464 $_ = int; # Chop non-integer part
465 1 while
466 s/(\d)(\d{$grouping[0]}($|$thousands_sep))/$1$thousands_sep$2/;
467 print &quot;$_&quot;;
469 print &quot;\n&quot;;</pre>
471 </p>
472 <h2><a name="i18n__langinfo">I18N::Langinfo</a></h2>
473 <p>Another interface for querying locale-dependent information is the
474 I18N::Langinfo::langinfo() function, available at least in UNIX-like
475 systems and VMS.</p>
476 <p>The following example will import the <code>langinfo()</code> function itself and
477 three constants to be used as arguments to langinfo(): a constant for
478 the abbreviated first day of the week (the numbering starts from
479 Sunday = 1) and two more constants for the affirmative and negative
480 answers for a yes/no question in the current locale.</p>
481 <pre>
482 use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR);</pre>
483 <pre>
484 my ($abday_1, $yesstr, $nostr) = map { langinfo } qw(ABDAY_1 YESSTR NOSTR);</pre>
485 <pre>
486 print &quot;$abday_1? [$yesstr/$nostr] &quot;;</pre>
487 <p>In other words, in the ``C'' (or English) locale the above will probably
488 print something like:</p>
489 <pre>
490 Sun? [yes/no]</pre>
491 <p>See <a href="file://C|\msysgit\mingw\html/I18N/Langinfo.html">the I18N::Langinfo manpage</a> for more information.</p>
493 </p>
494 <hr />
495 <h1><a name="locale_categories">LOCALE CATEGORIES</a></h1>
496 <p>The following subsections describe basic locale categories. Beyond these,
497 some combination categories allow manipulation of more than one
498 basic category at a time. See <a href="#environment">ENVIRONMENT</a> for a discussion of these.</p>
500 </p>
501 <h2><a name="category_lc_collate__collation">Category LC_COLLATE: Collation</a></h2>
502 <p>In the scope of <code>use&nbsp;locale</code>, Perl looks to the <a href="#item_lc_collate"><code>LC_COLLATE</code></a>
503 environment variable to determine the application's notions on collation
504 (ordering) of characters. For example, 'b' follows 'a' in Latin
505 alphabets, but where do '&aacute;' and '&aring;' belong? And while
506 'color' follows 'chocolate' in English, what about in Spanish?</p>
507 <p>The following collations all make sense and you may meet any of them
508 if you ``use locale''.</p>
509 <pre>
510 A B C D E a b c d e
511 A a B b C c D d E e
512 a A b B c C d D e E
513 a b c d e A B C D E</pre>
514 <p>Here is a code snippet to tell what ``word''
515 characters are in the current locale, in that locale's order:</p>
516 <pre>
517 use locale;
518 print +(sort grep /\w/, map { chr } 0..255), &quot;\n&quot;;</pre>
519 <p>Compare this with the characters that you see and their order if you
520 state explicitly that the locale should be ignored:</p>
521 <pre>
522 no locale;
523 print +(sort grep /\w/, map { chr } 0..255), &quot;\n&quot;;</pre>
524 <p>This machine-native collation (which is what you get unless <code>use
525 locale</code> has appeared earlier in the same block) must be used for
526 sorting raw binary data, whereas the locale-dependent collation of the
527 first example is useful for natural text.</p>
528 <p>As noted in <a href="#using_locales">USING LOCALES</a>, <code>cmp</code> compares according to the current
529 collation locale when <code>use locale</code> is in effect, but falls back to a
530 char-by-char comparison for strings that the locale says are equal. You
531 can use POSIX::strcoll() if you don't want this fall-back:</p>
532 <pre>
533 use POSIX qw(strcoll);
534 $equal_in_locale =
535 !strcoll(&quot;space and case ignored&quot;, &quot;SpaceAndCaseIgnored&quot;);</pre>
536 <p>$equal_in_locale will be true if the collation locale specifies a
537 dictionary-like ordering that ignores space characters completely and
538 which folds case.</p>
539 <p>If you have a single string that you want to check for ``equality in
540 locale'' against several others, you might think you could gain a little
541 efficiency by using POSIX::strxfrm() in conjunction with <code>eq</code>:</p>
542 <pre>
543 use POSIX qw(strxfrm);
544 $xfrm_string = strxfrm(&quot;Mixed-case string&quot;);
545 print &quot;locale collation ignores spaces\n&quot;
546 if $xfrm_string eq strxfrm(&quot;Mixed-casestring&quot;);
547 print &quot;locale collation ignores hyphens\n&quot;
548 if $xfrm_string eq strxfrm(&quot;Mixedcase string&quot;);
549 print &quot;locale collation ignores case\n&quot;
550 if $xfrm_string eq strxfrm(&quot;mixed-case string&quot;);</pre>
551 <p><code>strxfrm()</code> takes a string and maps it into a transformed string for use
552 in char-by-char comparisons against other transformed strings during
553 collation. ``Under the hood'', locale-affected Perl comparison operators
554 call <code>strxfrm()</code> for both operands, then do a char-by-char
555 comparison of the transformed strings. By calling <code>strxfrm()</code> explicitly
556 and using a non locale-affected comparison, the example attempts to save
557 a couple of transformations. But in fact, it doesn't save anything: Perl
558 magic (see <a href="file://C|\msysgit\mingw\html/pod/perlguts.html#magic_variables">Magic Variables in the perlguts manpage</a>) creates the transformed version of a
559 string the first time it's needed in a comparison, then keeps this version around
560 in case it's needed again. An example rewritten the easy way with
561 <code>cmp</code> runs just about as fast. It also copes with null characters
562 embedded in strings; if you call <code>strxfrm()</code> directly, it treats the first
563 null it finds as a terminator. don't expect the transformed strings
564 it produces to be portable across systems--or even from one revision
565 of your operating system to the next. In short, don't call <code>strxfrm()</code>
566 directly: let Perl do it for you.</p>
567 <p>Note: <code>use locale</code> isn't shown in some of these examples because it isn't
568 needed: <code>strcoll()</code> and <code>strxfrm()</code> exist only to generate locale-dependent
569 results, and so always obey the current <a href="#item_lc_collate"><code>LC_COLLATE</code></a> locale.</p>
571 </p>
572 <h2><a name="category_lc_ctype__character_types">Category LC_CTYPE: Character Types</a></h2>
573 <p>In the scope of <code>use&nbsp;locale</code>, Perl obeys the <a href="#item_lc_ctype"><code>LC_CTYPE</code></a> locale
574 setting. This controls the application's notion of which characters are
575 alphabetic. This affects Perl's <code>\w</code> regular expression metanotation,
576 which stands for alphanumeric characters--that is, alphabetic,
577 numeric, and including other special characters such as the underscore or
578 hyphen. (Consult <a href="file://C|\msysgit\mingw\html/pod/perlre.html">the perlre manpage</a> for more information about
579 regular expressions.) Thanks to <a href="#item_lc_ctype"><code>LC_CTYPE</code></a>, depending on your locale
580 setting, characters like '&aelig;', '&eth;', '&szlig;', and
581 '&oslash;' may be understood as <code>\w</code> characters.</p>
582 <p>The <a href="#item_lc_ctype"><code>LC_CTYPE</code></a> locale also provides the map used in transliterating
583 characters between lower and uppercase. This affects the case-mapping
584 functions--lc(), lcfirst, uc(), and ucfirst(); case-mapping
585 interpolation with <code>\l</code>, <code>\L</code>, <code>\u</code>, or <code>\U</code> in double-quoted strings
586 and <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_s_"><code>s///</code></a> substitutions; and case-independent regular expression
587 pattern matching using the <code>i</code> modifier.</p>
588 <p>Finally, <a href="#item_lc_ctype"><code>LC_CTYPE</code></a> affects the POSIX character-class test
589 functions--isalpha(), islower(), and so on. For example, if you move
590 from the ``C'' locale to a 7-bit Scandinavian one, you may find--possibly
591 to your surprise--that ``|'' moves from the <code>ispunct()</code> class to isalpha().</p>
592 <p><strong>Note:</strong> A broken or malicious <a href="#item_lc_ctype"><code>LC_CTYPE</code></a> locale definition may result
593 in clearly ineligible characters being considered to be alphanumeric by
594 your application. For strict matching of (mundane) letters and
595 digits--for example, in command strings--locale-aware applications
596 should use <code>\w</code> inside a <code>no locale</code> block. See <a href="#security">SECURITY</a>.</p>
598 </p>
599 <h2><a name="category_lc_numeric__numeric_formatting">Category LC_NUMERIC: Numeric Formatting</a></h2>
600 <p>In the scope of <code>use&nbsp;locale</code>, Perl obeys the <a href="#item_lc_numeric"><code>LC_NUMERIC</code></a> locale
601 information, which controls an application's idea of how numbers should
602 be formatted for human readability by the printf(), sprintf(), and
603 <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_write"><code>write()</code></a> functions. String-to-numeric conversion by the POSIX::strtod()
604 function is also affected. In most implementations the only effect is to
605 change the character used for the decimal point--perhaps from '.' to ','.
606 These functions aren't aware of such niceties as thousands separation and
607 so on. (See <a href="#the_localeconv_function">The localeconv function</a> if you care about these things.)</p>
608 <p>Output produced by <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_print"><code>print()</code></a> is also affected by the current locale: it
609 depends on whether <code>use locale</code> or <code>no locale</code> is in effect, and
610 corresponds to what you'd get from <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_printf"><code>printf()</code></a> in the ``C'' locale. The
611 same is true for Perl's internal conversions between numeric and
612 string formats:</p>
613 <pre>
614 use POSIX qw(strtod);
615 use locale;</pre>
616 <pre>
617 $n = 5/2; # Assign numeric 2.5 to $n</pre>
618 <pre>
619 $a = &quot; $n&quot;; # Locale-dependent conversion to string</pre>
620 <pre>
621 print &quot;half five is $n\n&quot;; # Locale-dependent output</pre>
622 <pre>
623 printf &quot;half five is %g\n&quot;, $n; # Locale-dependent output</pre>
624 <pre>
625 print &quot;DECIMAL POINT IS COMMA\n&quot;
626 if $n == (strtod(&quot;2,5&quot;))[0]; # Locale-dependent conversion</pre>
627 <p>See also <a href="file://C|\msysgit\mingw\html/I18N/Langinfo.html">the I18N::Langinfo manpage</a> and <code>RADIXCHAR</code>.</p>
629 </p>
630 <h2><a name="category_lc_monetary__formatting_of_monetary_amounts">Category LC_MONETARY: Formatting of monetary amounts</a></h2>
631 <p>The C standard defines the <a href="#item_lc_monetary"><code>LC_MONETARY</code></a> category, but no function
632 that is affected by its contents. (Those with experience of standards
633 committees will recognize that the working group decided to punt on the
634 issue.) Consequently, Perl takes no notice of it. If you really want
635 to use <a href="#item_lc_monetary"><code>LC_MONETARY</code></a>, you can query its contents--see
636 <a href="#the_localeconv_function">The localeconv function</a>--and use the information that it returns in your
637 application's own formatting of currency amounts. However, you may well
638 find that the information, voluminous and complex though it may be, still
639 does not quite meet your requirements: currency formatting is a hard nut
640 to crack.</p>
641 <p>See also <a href="file://C|\msysgit\mingw\html/I18N/Langinfo.html">the I18N::Langinfo manpage</a> and <code>CRNCYSTR</code>.</p>
643 </p>
644 <h2><a name="lc_time">LC_TIME</a></h2>
645 <p>Output produced by POSIX::strftime(), which builds a formatted
646 human-readable date/time string, is affected by the current <a href="#item_lc_time"><code>LC_TIME</code></a>
647 locale. Thus, in a French locale, the output produced by the <code>%B</code>
648 format element (full month name) for the first month of the year would
649 be ``janvier''. Here's how to get a list of long month names in the
650 current locale:</p>
651 <pre>
652 use POSIX qw(strftime);
653 for (0..11) {
654 $long_month_name[$_] =
655 strftime(&quot;%B&quot;, 0, 0, 0, 1, $_, 96);
656 }</pre>
657 <p>Note: <code>use locale</code> isn't needed in this example: as a function that
658 exists only to generate locale-dependent results, <code>strftime()</code> always
659 obeys the current <a href="#item_lc_time"><code>LC_TIME</code></a> locale.</p>
660 <p>See also <a href="file://C|\msysgit\mingw\html/I18N/Langinfo.html">the I18N::Langinfo manpage</a> and <code>ABDAY_1</code>..<code>ABDAY_7</code>, <code>DAY_1</code>..<code>DAY_7</code>,
661 <code>ABMON_1</code>..<code>ABMON_12</code>, and <code>ABMON_1</code>..<code>ABMON_12</code>.</p>
663 </p>
664 <h2><a name="other_categories">Other categories</a></h2>
665 <p>The remaining locale category, <code>LC_MESSAGES</code> (possibly supplemented
666 by others in particular implementations) is not currently used by
667 Perl--except possibly to affect the behavior of library functions
668 called by extensions outside the standard Perl distribution and by the
669 operating system and its utilities. Note especially that the string
670 value of <a href="file://C|\msysgit\mingw\html/pod/perlvar.html#item___"><code>$!</code></a> and the error messages given by external utilities may
671 be changed by <code>LC_MESSAGES</code>. If you want to have portable error
672 codes, use <a href="file://C|\msysgit\mingw\html/pod/perlvar.html#item___"><code>%!</code></a>. See <a href="file://C|\msysgit\mingw\html/lib/Errno.html">the Errno manpage</a>.</p>
674 </p>
675 <hr />
676 <h1><a name="security">SECURITY</a></h1>
677 <p>Although the main discussion of Perl security issues can be found in
678 <a href="file://C|\msysgit\mingw\html/pod/perlsec.html">the perlsec manpage</a>, a discussion of Perl's locale handling would be incomplete
679 if it did not draw your attention to locale-dependent security issues.
680 Locales--particularly on systems that allow unprivileged users to
681 build their own locales--are untrustworthy. A malicious (or just plain
682 broken) locale can make a locale-aware application give unexpected
683 results. Here are a few possibilities:</p>
684 <ul>
685 <li>
686 <p>Regular expression checks for safe file names or mail addresses using
687 <code>\w</code> may be spoofed by an <a href="#item_lc_ctype"><code>LC_CTYPE</code></a> locale that claims that
688 characters such as ``&gt;'' and ``|'' are alphanumeric.</p>
689 </li>
690 <li>
691 <p>String interpolation with case-mapping, as in, say, <code>$dest =
692 &quot;C:\U$name.$ext&quot;</code>, may produce dangerous results if a bogus LC_CTYPE
693 case-mapping table is in effect.</p>
694 </li>
695 <li>
696 <p>A sneaky <a href="#item_lc_collate"><code>LC_COLLATE</code></a> locale could result in the names of students with
697 ``D'' grades appearing ahead of those with ``A''s.</p>
698 </li>
699 <li>
700 <p>An application that takes the trouble to use information in
701 <a href="#item_lc_monetary"><code>LC_MONETARY</code></a> may format debits as if they were credits and vice versa
702 if that locale has been subverted. Or it might make payments in US
703 dollars instead of Hong Kong dollars.</p>
704 </li>
705 <li>
706 <p>The date and day names in dates formatted by <code>strftime()</code> could be
707 manipulated to advantage by a malicious user able to subvert the
708 <code>LC_DATE</code> locale. (``Look--it says I wasn't in the building on
709 Sunday.'')</p>
710 </li>
711 </ul>
712 <p>Such dangers are not peculiar to the locale system: any aspect of an
713 application's environment which may be modified maliciously presents
714 similar challenges. Similarly, they are not specific to Perl: any
715 programming language that allows you to write programs that take
716 account of their environment exposes you to these issues.</p>
717 <p>Perl cannot protect you from all possibilities shown in the
718 examples--there is no substitute for your own vigilance--but, when
719 <code>use locale</code> is in effect, Perl uses the tainting mechanism (see
720 <a href="file://C|\msysgit\mingw\html/pod/perlsec.html">the perlsec manpage</a>) to mark string results that become locale-dependent, and
721 which may be untrustworthy in consequence. Here is a summary of the
722 tainting behavior of operators and functions that may be affected by
723 the locale:</p>
724 <ul>
725 <li>
726 <p><strong>Comparison operators</strong> (<code>lt</code>, <code>le</code>, <code>ge</code>, <code>gt</code> and <code>cmp</code>):</p>
727 <p>Scalar true/false (or less/equal/greater) result is never tainted.</p>
728 </li>
729 <li>
730 <p><strong>Case-mapping interpolation</strong> (with <code>\l</code>, <code>\L</code>, <code>\u</code> or <code>\U</code>)</p>
731 <p>Result string containing interpolated material is tainted if
732 <code>use locale</code> is in effect.</p>
733 </li>
734 <li>
735 <p><strong>Matching operator</strong> (<a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_m_"><code>m//</code></a>):</p>
736 <p>Scalar true/false result never tainted.</p>
737 <p>Subpatterns, either delivered as a list-context result or as $1 etc.
738 are tainted if <code>use locale</code> is in effect, and the subpattern regular
739 expression contains <code>\w</code> (to match an alphanumeric character), <code>\W</code>
740 (non-alphanumeric character), <code>\s</code> (whitespace character), or <code>\S</code>
741 (non whitespace character). The matched-pattern variable, $&amp;, $`
742 (pre-match), $' (post-match), and $+ (last match) are also tainted if
743 <code>use locale</code> is in effect and the regular expression contains <code>\w</code>,
744 <code>\W</code>, <code>\s</code>, or <code>\S</code>.</p>
745 </li>
746 <li>
747 <p><strong>Substitution operator</strong> (<a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_s_"><code>s///</code></a>):</p>
748 <p>Has the same behavior as the match operator. Also, the left
749 operand of <code>=~</code> becomes tainted when <code>use locale</code> in effect
750 if modified as a result of a substitution based on a regular
751 expression match involving <code>\w</code>, <code>\W</code>, <code>\s</code>, or <code>\S</code>; or of
752 case-mapping with <code>\l</code>, <code>\L</code>,<code>\u</code> or <code>\U</code>.</p>
753 </li>
754 <li>
755 <p><strong>Output formatting functions</strong> (printf() and write()):</p>
756 <p>Results are never tainted because otherwise even output from print,
757 for example <a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_print"><code>print(1/7)</code></a>, should be tainted if <code>use locale</code> is in
758 effect.</p>
759 </li>
760 <li>
761 <p><strong>Case-mapping functions</strong> (lc(), lcfirst(), uc(), ucfirst()):</p>
762 <p>Results are tainted if <code>use locale</code> is in effect.</p>
763 </li>
764 <li>
765 <p><strong>POSIX locale-dependent functions</strong> (localeconv(), strcoll(),
766 strftime(), strxfrm()):</p>
767 <p>Results are never tainted.</p>
768 </li>
769 <li>
770 <p><strong>POSIX character class tests</strong> (isalnum(), isalpha(), isdigit(),
771 isgraph(), islower(), isprint(), ispunct(), isspace(), isupper(),
772 isxdigit()):</p>
773 <p>True/false results are never tainted.</p>
774 </li>
775 </ul>
776 <p>Three examples illustrate locale-dependent tainting.
777 The first program, which ignores its locale, won't run: a value taken
778 directly from the command line may not be used to name an output file
779 when taint checks are enabled.</p>
780 <pre>
781 #/usr/local/bin/perl -T
782 # Run with taint checking</pre>
783 <pre>
784 # Command line sanity check omitted...
785 $tainted_output_file = shift;</pre>
786 <pre>
787 open(F, &quot;&gt;$tainted_output_file&quot;)
788 or warn &quot;Open of $untainted_output_file failed: $!\n&quot;;</pre>
789 <p>The program can be made to run by ``laundering'' the tainted value through
790 a regular expression: the second example--which still ignores locale
791 information--runs, creating the file named on its command line
792 if it can.</p>
793 <pre>
794 #/usr/local/bin/perl -T</pre>
795 <pre>
796 $tainted_output_file = shift;
797 $tainted_output_file =~ m%[\w/]+%;
798 $untainted_output_file = $&amp;;</pre>
799 <pre>
800 open(F, &quot;&gt;$untainted_output_file&quot;)
801 or warn &quot;Open of $untainted_output_file failed: $!\n&quot;;</pre>
802 <p>Compare this with a similar but locale-aware program:</p>
803 <pre>
804 #/usr/local/bin/perl -T</pre>
805 <pre>
806 $tainted_output_file = shift;
807 use locale;
808 $tainted_output_file =~ m%[\w/]+%;
809 $localized_output_file = $&amp;;</pre>
810 <pre>
811 open(F, &quot;&gt;$localized_output_file&quot;)
812 or warn &quot;Open of $localized_output_file failed: $!\n&quot;;</pre>
813 <p>This third program fails to run because $&amp; is tainted: it is the result
814 of a match involving <code>\w</code> while <code>use locale</code> is in effect.</p>
816 </p>
817 <hr />
818 <h1><a name="environment">ENVIRONMENT</a></h1>
819 <dl>
820 <dt><strong><a name="item_perl_badlang">PERL_BADLANG</a></strong>
822 <dd>
823 <p>A string that can suppress Perl's warning about failed locale settings
824 at startup. Failure can occur if the locale support in the operating
825 system is lacking (broken) in some way--or if you mistyped the name of
826 a locale when you set up your environment. If this environment
827 variable is absent, or has a value that does not evaluate to integer
828 zero--that is, ``0'' or ``''-- Perl will complain about locale setting
829 failures.</p>
830 </dd>
831 <dd>
832 <p><strong>NOTE</strong>: PERL_BADLANG only gives you a way to hide the warning message.
833 The message tells about some problem in your system's locale support,
834 and you should investigate what the problem is.</p>
835 </dd>
836 </li>
837 </dl>
838 <p>The following environment variables are not specific to Perl: They are
839 part of the standardized (ISO C, XPG4, POSIX 1.c) <code>setlocale()</code> method
840 for controlling an application's opinion on data.</p>
841 <dl>
842 <dt><strong><a name="item_lc_all">LC_ALL</a></strong>
844 <dd>
845 <p><a href="#item_lc_all"><code>LC_ALL</code></a> is the ``override-all'' locale environment variable. If
846 set, it overrides all the rest of the locale environment variables.</p>
847 </dd>
848 </li>
849 <dt><strong><a name="item_language">LANGUAGE</a></strong>
851 <dd>
852 <p><strong>NOTE</strong>: <a href="#item_language"><code>LANGUAGE</code></a> is a GNU extension, it affects you only if you
853 are using the GNU libc. This is the case if you are using e.g. Linux.
854 If you are using ``commercial'' UNIXes you are most probably <em>not</em>
855 using GNU libc and you can ignore <a href="#item_language"><code>LANGUAGE</code></a>.</p>
856 </dd>
857 <dd>
858 <p>However, in the case you are using <a href="#item_language"><code>LANGUAGE</code></a>: it affects the
859 language of informational, warning, and error messages output by
860 commands (in other words, it's like <code>LC_MESSAGES</code>) but it has higher
861 priority than <a href="#item_lc_all">LC_ALL</a>. Moreover, it's not a single value but
862 instead a ``path'' (``:''-separated list) of <em>languages</em> (not locales).
863 See the GNU <code>gettext</code> library documentation for more information.</p>
864 </dd>
865 </li>
866 <dt><strong><a name="item_lc_ctype">LC_CTYPE</a></strong>
868 <dd>
869 <p>In the absence of <a href="#item_lc_all"><code>LC_ALL</code></a>, <a href="#item_lc_ctype"><code>LC_CTYPE</code></a> chooses the character type
870 locale. In the absence of both <a href="#item_lc_all"><code>LC_ALL</code></a> and <a href="#item_lc_ctype"><code>LC_CTYPE</code></a>, <a href="#item_lang"><code>LANG</code></a>
871 chooses the character type locale.</p>
872 </dd>
873 </li>
874 <dt><strong><a name="item_lc_collate">LC_COLLATE</a></strong>
876 <dd>
877 <p>In the absence of <a href="#item_lc_all"><code>LC_ALL</code></a>, <a href="#item_lc_collate"><code>LC_COLLATE</code></a> chooses the collation
878 (sorting) locale. In the absence of both <a href="#item_lc_all"><code>LC_ALL</code></a> and <a href="#item_lc_collate"><code>LC_COLLATE</code></a>,
879 <a href="#item_lang"><code>LANG</code></a> chooses the collation locale.</p>
880 </dd>
881 </li>
882 <dt><strong><a name="item_lc_monetary">LC_MONETARY</a></strong>
884 <dd>
885 <p>In the absence of <a href="#item_lc_all"><code>LC_ALL</code></a>, <a href="#item_lc_monetary"><code>LC_MONETARY</code></a> chooses the monetary
886 formatting locale. In the absence of both <a href="#item_lc_all"><code>LC_ALL</code></a> and <a href="#item_lc_monetary"><code>LC_MONETARY</code></a>,
887 <a href="#item_lang"><code>LANG</code></a> chooses the monetary formatting locale.</p>
888 </dd>
889 </li>
890 <dt><strong><a name="item_lc_numeric">LC_NUMERIC</a></strong>
892 <dd>
893 <p>In the absence of <a href="#item_lc_all"><code>LC_ALL</code></a>, <a href="#item_lc_numeric"><code>LC_NUMERIC</code></a> chooses the numeric format
894 locale. In the absence of both <a href="#item_lc_all"><code>LC_ALL</code></a> and <a href="#item_lc_numeric"><code>LC_NUMERIC</code></a>, <a href="#item_lang"><code>LANG</code></a>
895 chooses the numeric format.</p>
896 </dd>
897 </li>
898 <dt><strong><a name="item_lc_time">LC_TIME</a></strong>
900 <dd>
901 <p>In the absence of <a href="#item_lc_all"><code>LC_ALL</code></a>, <a href="#item_lc_time"><code>LC_TIME</code></a> chooses the date and time
902 formatting locale. In the absence of both <a href="#item_lc_all"><code>LC_ALL</code></a> and <a href="#item_lc_time"><code>LC_TIME</code></a>,
903 <a href="#item_lang"><code>LANG</code></a> chooses the date and time formatting locale.</p>
904 </dd>
905 </li>
906 <dt><strong><a name="item_lang">LANG</a></strong>
908 <dd>
909 <p><a href="#item_lang"><code>LANG</code></a> is the ``catch-all'' locale environment variable. If it is set, it
910 is used as the last resort after the overall <a href="#item_lc_all"><code>LC_ALL</code></a> and the
911 category-specific <code>LC_...</code>.</p>
912 </dd>
913 </li>
914 </dl>
916 </p>
917 <hr />
918 <h1><a name="notes">NOTES</a></h1>
920 </p>
921 <h2><a name="backward_compatibility">Backward compatibility</a></h2>
922 <p>Versions of Perl prior to 5.004 <strong>mostly</strong> ignored locale information,
923 generally behaving as if something similar to the <code>&quot;C&quot;</code> locale were
924 always in force, even if the program environment suggested otherwise
925 (see <a href="#the_setlocale_function">The setlocale function</a>). By default, Perl still behaves this
926 way for backward compatibility. If you want a Perl application to pay
927 attention to locale information, you <strong>must</strong> use the <code>use&nbsp;locale</code>
928 pragma (see <a href="#the_use_locale_pragma">The use locale pragma</a>) to instruct it to do so.</p>
929 <p>Versions of Perl from 5.002 to 5.003 did use the <a href="#item_lc_ctype"><code>LC_CTYPE</code></a>
930 information if available; that is, <code>\w</code> did understand what
931 were the letters according to the locale environment variables.
932 The problem was that the user had no control over the feature:
933 if the C library supported locales, Perl used them.</p>
935 </p>
936 <h2><a name="i18n_collate_obsolete">I18N:Collate obsolete</a></h2>
937 <p>In versions of Perl prior to 5.004, per-locale collation was possible
938 using the <code>I18N::Collate</code> library module. This module is now mildly
939 obsolete and should be avoided in new applications. The <a href="#item_lc_collate"><code>LC_COLLATE</code></a>
940 functionality is now integrated into the Perl core language: One can
941 use locale-specific scalar data completely normally with <code>use locale</code>,
942 so there is no longer any need to juggle with the scalar references of
943 <code>I18N::Collate</code>.</p>
945 </p>
946 <h2><a name="sort_speed_and_memory_use_impacts">Sort speed and memory use impacts</a></h2>
947 <p>Comparing and sorting by locale is usually slower than the default
948 sorting; slow-downs of two to four times have been observed. It will
949 also consume more memory: once a Perl scalar variable has participated
950 in any string comparison or sorting operation obeying the locale
951 collation rules, it will take 3-15 times more memory than before. (The
952 exact multiplier depends on the string's contents, the operating system
953 and the locale.) These downsides are dictated more by the operating
954 system's implementation of the locale system than by Perl.</p>
956 </p>
957 <h2><a name="write___and_lc_numeric"><a href="file://C|\msysgit\mingw\html/pod/perlfunc.html#item_write"><code>write()</code></a> and LC_NUMERIC</a></h2>
958 <p>Formats are the only part of Perl that unconditionally use information
959 from a program's locale; if a program's environment specifies an
960 LC_NUMERIC locale, it is always used to specify the decimal point
961 character in formatted output. Formatted output cannot be controlled by
962 <code>use locale</code> because the pragma is tied to the block structure of the
963 program, and, for historical reasons, formats exist outside that block
964 structure.</p>
966 </p>
967 <h2><a name="freely_available_locale_definitions">Freely available locale definitions</a></h2>
968 <p>There is a large collection of locale definitions at
969 <a href="ftp://dkuug.dk/i18n/WG15-collection">ftp://dkuug.dk/i18n/WG15-collection</a> . You should be aware that it is
970 unsupported, and is not claimed to be fit for any purpose. If your
971 system allows installation of arbitrary locales, you may find the
972 definitions useful as they are, or as a basis for the development of
973 your own locales.</p>
975 </p>
976 <h2><a name="i18n_and_l10n">I18n and l10n</a></h2>
977 <p>``Internationalization'' is often abbreviated as <strong>i18n</strong> because its first
978 and last letters are separated by eighteen others. (You may guess why
979 the internalin ... internaliti ... i18n tends to get abbreviated.) In
980 the same way, ``localization'' is often abbreviated to <strong>l10n</strong>.</p>
982 </p>
983 <h2><a name="an_imperfect_standard">An imperfect standard</a></h2>
984 <p>Internationalization, as defined in the C and POSIX standards, can be
985 criticized as incomplete, ungainly, and having too large a granularity.
986 (Locales apply to a whole process, when it would arguably be more useful
987 to have them apply to a single thread, window group, or whatever.) They
988 also have a tendency, like standards groups, to divide the world into
989 nations, when we all know that the world can equally well be divided
990 into bankers, bikers, gamers, and so on. But, for now, it's the only
991 standard we've got. This may be construed as a bug.</p>
993 </p>
994 <hr />
995 <h1><a name="unicode_and_utf8">Unicode and UTF-8</a></h1>
996 <p>The support of Unicode is new starting from Perl version 5.6, and
997 more fully implemented in the version 5.8. See <a href="file://C|\msysgit\mingw\html/pod/perluniintro.html">the perluniintro manpage</a> and
998 <a href="file://C|\msysgit\mingw\html/pod/perlunicode.html">the perlunicode manpage</a> for more details.</p>
999 <p>Usually locale settings and Unicode do not affect each other, but
1000 there are exceptions, see <a href="file://C|\msysgit\mingw\html/pod/perlunicode.html#locales">Locales in the perlunicode manpage</a> for examples.</p>
1002 </p>
1003 <hr />
1004 <h1><a name="bugs">BUGS</a></h1>
1006 </p>
1007 <h2><a name="broken_systems">Broken systems</a></h2>
1008 <p>In certain systems, the operating system's locale support
1009 is broken and cannot be fixed or used by Perl. Such deficiencies can
1010 and will result in mysterious hangs and/or Perl core dumps when the
1011 <code>use locale</code> is in effect. When confronted with such a system,
1012 please report in excruciating detail to &lt;<em><a href="mailto:perlbug@perl.org">perlbug@perl.org</a></em>&gt;, and
1013 complain to your vendor: bug fixes may exist for these problems
1014 in your operating system. Sometimes such bug fixes are called an
1015 operating system upgrade.</p>
1017 </p>
1018 <hr />
1019 <h1><a name="see_also">SEE ALSO</a></h1>
1020 <p><a href="file://C|\msysgit\mingw\html/I18N/Langinfo.html">the I18N::Langinfo manpage</a>, <a href="file://C|\msysgit\mingw\html/pod/perluniintro.html">the perluniintro manpage</a>, <a href="file://C|\msysgit\mingw\html/pod/perlunicode.html">the perlunicode manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/open.html">the open manpage</a>,
1021 <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/isalnum.html">isalnum in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/isalpha.html">isalpha in the POSIX manpage</a>,
1022 <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/isdigit.html">isdigit in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/isgraph.html">isgraph in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/islower.html">islower in the POSIX manpage</a>,
1023 <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/isprint.html">isprint in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/ispunct.html">ispunct in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/isspace.html">isspace in the POSIX manpage</a>,
1024 <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/isupper.html">isupper in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/isxdigit.html">isxdigit in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/localeconv.html">localeconv in the POSIX manpage</a>,
1025 <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/setlocale.html">setlocale in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/strcoll.html">strcoll in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/strftime.html">strftime in the POSIX manpage</a>,
1026 <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/strtod.html">strtod in the POSIX manpage</a>, <a href="file://C|\msysgit\mingw\html/lib/auto/POSIX/strxfrm.html">strxfrm in the POSIX manpage</a>.</p>
1028 </p>
1029 <hr />
1030 <h1><a name="history">HISTORY</a></h1>
1031 <p>Jarkko Hietaniemi's original <em>perli18n.pod</em> heavily hacked by Dominic
1032 Dunlop, assisted by the perl5-porters. Prose worked over a bit by
1033 Tom Christiansen.</p>
1034 <p>Last update: Thu Jun 11 08:44:13 MDT 1998</p>
1035 <table border="0" width="100%" cellspacing="0" cellpadding="3">
1036 <tr><td class="block" style="background-color: #cccccc" valign="middle">
1037 <big><strong><span class="block">&nbsp;perllocale - Perl locale handling</span></strong></big>
1038 </td></tr>
1039 </table>
1041 </body>
1043 </html>