perllocale.html
来自「perl教程」· HTML 代码 · 共 1,009 行 · 第 1/5 页
HTML
1,009 行
<?xml version="1.0" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!-- saved from url=(0017)http://localhost/ -->
<script language="JavaScript" src="../../displayToc.js"></script>
<script language="JavaScript" src="../../tocParas.js"></script>
<script language="JavaScript" src="../../tocTab.js"></script>
<link rel="stylesheet" type="text/css" href="../../scineplex.css">
<title>perllocale - Perl locale handling</title>
<link rel="stylesheet" href="../../Active.css" type="text/css" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rev="made" href="mailto:" />
</head>
<body>
<script>writelinks('__top__',2);</script>
<h1><a>perllocale - Perl locale handling</a></h1>
<p><a name="__index__"></a></p>
<!-- INDEX BEGIN -->
<ul>
<li><a href="#name">NAME</a></li>
<li><a href="#description">DESCRIPTION</a></li>
<li><a href="#preparing_to_use_locales">PREPARING TO USE LOCALES</a></li>
<li><a href="#using_locales">USING LOCALES</a></li>
<ul>
<li><a href="#the_use_locale_pragma">The use locale pragma</a></li>
<li><a href="#the_setlocale_function">The setlocale function</a></li>
<li><a href="#finding_locales">Finding locales</a></li>
<li><a href="#locale_problems">LOCALE PROBLEMS</a></li>
<li><a href="#temporarily_fixing_locale_problems">Temporarily fixing locale problems</a></li>
<li><a href="#permanently_fixing_locale_problems">Permanently fixing locale problems</a></li>
<li><a href="#permanently_fixing_your_system_s_locale_configuration">Permanently fixing your system's locale configuration</a></li>
<li><a href="#fixing_system_locale_configuration">Fixing system locale configuration</a></li>
<li><a href="#the_localeconv_function">The localeconv function</a></li>
<li><a href="#i18n__langinfo">I18N::Langinfo</a></li>
</ul>
<li><a href="#locale_categories">LOCALE CATEGORIES</a></li>
<ul>
<li><a href="#category_lc_collate__collation">Category LC_COLLATE: Collation</a></li>
<li><a href="#category_lc_ctype__character_types">Category LC_CTYPE: Character Types</a></li>
<li><a href="#category_lc_numeric__numeric_formatting">Category LC_NUMERIC: Numeric Formatting</a></li>
<li><a href="#category_lc_monetary__formatting_of_monetary_amounts">Category LC_MONETARY: Formatting of monetary amounts</a></li>
<li><a href="#lc_time">LC_TIME</a></li>
<li><a href="#other_categories">Other categories</a></li>
</ul>
<li><a href="#security">SECURITY</a></li>
<li><a href="#environment">ENVIRONMENT</a></li>
<li><a href="#notes">NOTES</a></li>
<ul>
<li><a href="#backward_compatibility">Backward compatibility</a></li>
<li><a href="#i18n_collate_obsolete">I18N:Collate obsolete</a></li>
<li><a href="#sort_speed_and_memory_use_impacts">Sort speed and memory use impacts</a></li>
<li><a href="#write___and_lc_numeric"><a href="../../lib/Pod/perlfunc.html#item_write"><code>write()</code></a> and LC_NUMERIC</a></li>
<li><a href="#freely_available_locale_definitions">Freely available locale definitions</a></li>
<li><a href="#i18n_and_l10n">I18n and l10n</a></li>
<li><a href="#an_imperfect_standard">An imperfect standard</a></li>
</ul>
<li><a href="#unicode_and_utf8">Unicode and UTF-8</a></li>
<li><a href="#bugs">BUGS</a></li>
<ul>
<li><a href="#broken_systems">Broken systems</a></li>
</ul>
<li><a href="#see_also">SEE ALSO</a></li>
<li><a href="#history">HISTORY</a></li>
</ul>
<!-- INDEX END -->
<hr />
<p>
</p>
<h1><a name="name">NAME</a></h1>
<p>perllocale - Perl locale handling (internationalization and localization)</p>
<p>
</p>
<hr />
<h1><a name="description">DESCRIPTION</a></h1>
<p>Perl supports language-specific notions of data such as "is this
a letter", "what is the uppercase equivalent of this letter", and
"which of these letters comes first". These are important issues,
especially for languages other than English--but also for English: it
would be naïve to imagine that <code>A-Za-z</code> defines all the "letters"
needed to write in English. Perl is also aware that some character other
than '.' may be preferred as a decimal point, and that output date
representations may be language-specific. The process of making an
application take account of its users' preferences in such matters is
called <strong>internationalization</strong> (often abbreviated as <strong>i18n</strong>); telling
such an application about a particular set of preferences is known as
<strong>localization</strong> (<strong>l10n</strong>).</p>
<p>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 one pragma, one function call, and
several environment variables.</p>
<p><strong>NOTE</strong>: This feature is new in Perl 5.004, and does not apply unless an
application specifically requests it--see <a href="#backward_compatibility">Backward compatibility</a>.
The one exception is that <a href="../../lib/Pod/perlfunc.html#item_write"><code>write()</code></a> now <strong>always</strong> uses the current locale
- see <a href="#notes">NOTES</a>.</p>
<p>
</p>
<hr />
<h1><a name="preparing_to_use_locales">PREPARING TO USE LOCALES</a></h1>
<p>If Perl applications are to understand and present your data
correctly according a locale of your choice, <strong>all</strong> of the following
must be true:</p>
<ul>
<li>
<p><strong>Your operating system must support the locale system</strong>. If it does,
you should find that the <code>setlocale()</code> function is a documented part of
its C library.</p>
</li>
<li>
<p><strong>Definitions for locales that you use must be installed</strong>. You, or
your system administrator, must make sure that this is the case. The
available locales, the location in which they are kept, and the manner
in which they are installed all vary from system to system. Some systems
provide only a few, hard-wired locales and do not allow more to be
added. Others allow you to add "canned" locales provided by the system
supplier. Still others allow you or the system administrator to define
and add arbitrary locales. (You may have to ask your supplier to
provide canned locales that are not delivered with your operating
system.) Read your system documentation for further illumination.</p>
</li>
<li>
<p><strong>Perl must believe that the locale system is supported</strong>. If it does,
<code>perl -V:d_setlocale</code> will say that the value for <code>d_setlocale</code> is
<code>define</code>.</p>
</li>
</ul>
<p>If you want a Perl application to process and present your data
according to a particular locale, the application code should include
the <code>use locale</code> pragma (see <a href="#the_use_locale_pragma">The use locale pragma</a>) where
appropriate, and <strong>at least one</strong> of the following must be true:</p>
<ul>
<li>
<p><strong>The locale-determining environment variables (see <a href="#environment">ENVIRONMENT</a>)
must be correctly set up</strong> at the time the application is started, either
by yourself or by whoever set up your system account.</p>
</li>
<li>
<p><strong>The application must set its own locale</strong> using the method described in
<a href="#the_setlocale_function">The setlocale function</a>.</p>
</li>
</ul>
<p>
</p>
<hr />
<h1><a name="using_locales">USING LOCALES</a></h1>
<p>
</p>
<h2><a name="the_use_locale_pragma">The use locale pragma</a></h2>
<p>By default, Perl ignores the current locale. The <code>use locale</code>
pragma tells Perl to use the current locale for some operations:</p>
<ul>
<li>
<p><strong>The comparison operators</strong> (<code>lt</code>, <code>le</code>, <code>cmp</code>, <code>ge</code>, and <code>gt</code>) and
the POSIX string collation functions <code>strcoll()</code> and <code>strxfrm()</code> use
<a href="#item_lc_collate"><code>LC_COLLATE</code></a>. <a href="../../lib/Pod/perlfunc.html#item_sort"><code>sort()</code></a> is also affected if used without an
explicit comparison function, because it uses <code>cmp</code> by default.</p>
<p><strong>Note:</strong> <code>eq</code> and <code>ne</code> are unaffected by locale: they always
perform a char-by-char comparison of their scalar operands. What's
more, if <code>cmp</code> finds that its operands are equal according to the
collation sequence specified by the current locale, it goes on to
perform a char-by-char comparison, and only returns <em>0</em> (equal) if the
operands are char-for-char identical. If you really want to know whether
two strings--which <code>eq</code> and <code>cmp</code> may consider different--are equal
as far as collation in the locale is concerned, see the discussion in
<a href="#category_lc_collate__collation">Category LC_COLLATE: Collation</a>.</p>
</li>
<li>
<p><strong>Regular expressions and case-modification functions</strong> (uc(), lc(),
ucfirst(), and <a href="../../lib/Pod/perlfunc.html#item_lcfirst"><code>lcfirst())</code></a> use <a href="#item_lc_ctype"><code>LC_CTYPE</code></a></p>
</li>
<li>
<p><strong>The formatting functions</strong> (printf(), <a href="../../lib/Pod/perlfunc.html#item_sprintf"><code>sprintf()</code></a> and <a href="../../lib/Pod/perlfunc.html#item_write"><code>write())</code></a> use
<a href="#item_lc_numeric"><code>LC_NUMERIC</code></a></p>
</li>
<li>
<p><strong>The POSIX date formatting function</strong> (strftime()) uses <a href="#item_lc_time"><code>LC_TIME</code></a>.</p>
</li>
</ul>
<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
<a href="#locale_categories">LOCALE CATEGORIES</a>.</p>
<p>The default behavior is restored with the <code>no locale</code> pragma, or
upon reaching the end of block enclosing <code>use locale</code>.</p>
<p>The string result of any operation that uses locale
information is tainted, as it is possible for a locale to be
untrustworthy. See <a href="#security">SECURITY</a>.</p>
<p>
</p>
<h2><a name="the_setlocale_function">The setlocale function</a></h2>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?