This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
There is no more a ~~ feature, noticed by Moritz Lenz
[perl5.git] / pod / perllocale.pod
index 5232eba..a0962fc 100644 (file)
@@ -99,11 +99,11 @@ C<LC_COLLATE>.  sort() is also affected if used without an
 explicit comparison function, because it uses C<cmp> by default.
 
 B<Note:> C<eq> and C<ne> are unaffected by locale: they always
-perform a byte-by-byte comparison of their scalar operands.  What's
+perform a char-by-char comparison of their scalar operands.  What's
 more, if C<cmp> finds that its operands are equal according to the
 collation sequence specified by the current locale, it goes on to
-perform a byte-by-byte comparison, and only returns I<0> (equal) if the
-operands are bit-for-bit identical.  If you really want to know whether
+perform a char-by-char comparison, and only returns I<0> (equal) if the
+operands are char-for-char identical.  If you really want to know whether
 two strings--which C<eq> and C<cmp> may consider different--are equal
 as far as collation in the locale is concerned, see the discussion in
 L<Category LC_COLLATE: Collation>.
@@ -177,7 +177,7 @@ subsequent call to setlocale().
 If no second argument is provided and the category is LC_ALL, the
 result is implementation-dependent.  It may be a string of
 concatenated locales names (separator also implementation-dependent)
-or a single locale name.  Please consult your L<setlocale(3)> for
+or a single locale name.  Please consult your setlocale(3) man page for
 details.
 
 If a second argument is given and it corresponds to a valid locale,
@@ -197,11 +197,11 @@ be noticed, depending on your system's C library.
 If the second argument does not correspond to a valid locale, the locale
 for the category is not changed, and the function returns I<undef>.
 
-For further information about the categories, consult L<setlocale(3)>.
+For further information about the categories, consult setlocale(3).
 
 =head2 Finding locales
 
-For locales available in your system, consult also L<setlocale(3)> to
+For locales available in your system, consult also setlocale(3) to
 see whether it leads to the list of available locales (search for the
 I<SEE ALSO> section).  If that fails, try the following command lines:
 
@@ -289,11 +289,11 @@ than the PERL_BADLANG approach, but setting LC_ALL (or
 other locale variables) may affect other programs as well, not just
 Perl.  In particular, external programs run from within Perl will see
 these changes.  If you make the new settings permanent (read on), all
-programs you run see the changes.  See L<ENVIRONMENT> for
+programs you run see the changes.  See L<"ENVIRONMENT"> for
 the full list of relevant environment variables and L<USING LOCALES>
 for their effects in Perl.  Effects in other programs are 
 easily deducible.  For example, the variable LC_COLLATE may well affect
-your B<sort> program (or whatever the program that arranges `records'
+your B<sort> program (or whatever the program that arranges "records"
 alphabetically in your system is called).
 
 You can test out changing these variables temporarily, and if the
@@ -310,6 +310,10 @@ locale "En_US"--and in Cshish shells (B<csh>, B<tcsh>)
 
        setenv LC_ALL en_US.ISO8859-1
 
+or if you have the "env" application you can do in any shell
+
+       env LC_ALL=en_US.ISO8859-1 perl ...
+
 If you do not know what shell you have, consult your local
 helpdesk or the equivalent.
 
@@ -427,25 +431,28 @@ parameters as integers correctly formatted in the current locale:
         }
         print "\n";
 
-=head2 I18::Langinfo
+=head2 I18N::Langinfo
 
 Another interface for querying locale-dependent information is the
 I18N::Langinfo::langinfo() function, available at least in UNIX-like
 systems and VMS.
 
-The following example will import the langinfo() function itself
-(implicitly) and (explicitly) three string constants: a string for the
-abbreviated first day of the week (the numbering starts from Sunday =
-1) and two strings for the affirmative and negative answers for a
-yes/no question in the current locale.
+The following example will import the langinfo() function itself and
+three constants to be used as arguments to langinfo(): a constant for
+the abbreviated first day of the week (the numbering starts from
+Sunday = 1) and two more constants for the affirmative and negative
+answers for a yes/no question in the current locale.
 
-    use I18N::Langinfo qw(ABDAY_1 YESSTR NOSTR);
+    use I18N::Langinfo qw(langinfo ABDAY_1 YESSTR NOSTR);
 
-    print ABDAY_1, "? [", YESSTR, "/", NOSTR, "] ";
+    my ($abday_1, $yesstr, $nostr) = map { langinfo } qw(ABDAY_1 YESSTR NOSTR);
 
-In other words, in the "C" (or English) locale the above will print:
+    print "$abday_1? [$yesstr/$nostr] ";
 
-    Sun? [y/n] 
+In other words, in the "C" (or English) locale the above will probably
+print something like:
+
+    Sun? [yes/no] 
 
 See L<I18N::Langinfo> for more information.
 
@@ -490,7 +497,7 @@ 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
-byte-by-byte comparison for strings that the locale says are equal. You
+char-by-char comparison for strings that the locale says are equal. You
 can use POSIX::strcoll() if you don't want this fall-back:
 
         use POSIX qw(strcoll);
@@ -515,9 +522,9 @@ efficiency by using POSIX::strxfrm() in conjunction with C<eq>:
             if $xfrm_string eq strxfrm("mixed-case string");
 
 strxfrm() takes a string and maps it into a transformed string for use
-in byte-by-byte comparisons against other transformed strings during
+in char-by-char comparisons against other transformed strings during
 collation.  "Under the hood", locale-affected Perl comparison operators
-call strxfrm() for both operands, then do a byte-by-byte
+call strxfrm() for both operands, then do a char-by-char
 comparison of the transformed strings.  By calling strxfrm() explicitly
 and using a non locale-affected comparison, the example attempts to save
 a couple of transformations.  But in fact, it doesn't save anything: Perl
@@ -633,7 +640,7 @@ exists only to generate locale-dependent results, strftime() always
 obeys the current C<LC_TIME> locale.
 
 See also L<I18N::Langinfo> and C<ABDAY_1>..C<ABDAY_7>, C<DAY_1>..C<DAY_7>,
-C<ABMON_1>..C<ABMON_12>, and C<ABMON_1>..C<ABMON_12>; and L<Time::Piece>.
+C<ABMON_1>..C<ABMON_12>, and C<ABMON_1>..C<ABMON_12>.
 
 =head2 Other categories
 
@@ -729,8 +736,8 @@ Scalar true/false result never tainted.
 Subpatterns, either delivered as a list-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), C<\W>
-(non-alphanumeric character), C<\s> (white-space character), or C<\S>
-(non white-space character).  The matched-pattern variable, $&, $`
+(non-alphanumeric character), C<\s> (whitespace character), or C<\S>
+(non whitespace 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>.
@@ -902,6 +909,23 @@ category-specific C<LC_...>.
 
 =back
 
+=head2 Examples
+
+The LC_NUMERIC controls the numeric output:
+
+        use locale;
+        use POSIX qw(locale_h); # Imports setlocale() and the LC_ constants.
+        setlocale(LC_NUMERIC, "fr_FR") or die "Pardon";
+        printf "%g\n", 1.23; # If the "fr_FR" succeeded, probably shows 1,23.
+
+and also how strings are parsed by POSIX::strtod() as numbers:
+
+        use locale;
+        use POSIX qw(locale_h strtod);
+        setlocale(LC_NUMERIC, "de_DE") or die "Entshuldigung";
+        my $x = strtod("2,34") + 5;
+        print $x, "\n"; # Probably shows 7,34.
+
 =head1 NOTES
 
 =head2 Backward compatibility
@@ -954,7 +978,7 @@ structure.
 =head2 Freely available locale definitions
 
 There is a large collection of locale definitions at
-C<ftp://dkuug.dk/i18n/WG15-collection>.  You should be aware that it is
+ftp://dkuug.dk/i18n/WG15-collection .  You should be aware that it is
 unsupported, and is not claimed to be fit for any purpose.  If your
 system allows installation of arbitrary locales, you may find the
 definitions useful as they are, or as a basis for the development of
@@ -978,6 +1002,15 @@ nations, when we all know that the world can equally well be divided
 into bankers, bikers, gamers, and so on.  But, for now, it's the only
 standard we've got.  This may be construed as a bug.
 
+=head1 Unicode and UTF-8
+
+The support of Unicode is new starting from Perl version 5.6, and
+more fully implemented in the version 5.8.  See L<perluniintro> and
+L<perlunicode> for more details.
+
+Usually locale settings and Unicode do not affect each other, but
+there are exceptions, see L<perlunicode/Locales> for examples.
+
 =head1 BUGS
 
 =head2 Broken systems
@@ -993,7 +1026,8 @@ operating system upgrade.
 
 =head1 SEE ALSO
 
-L<I18N::Langinfo>, L<POSIX/isalnum>, L<POSIX/isalpha>,
+L<I18N::Langinfo>, L<perluniintro>, L<perlunicode>, L<open>,
+L<POSIX/isalnum>, L<POSIX/isalpha>,
 L<POSIX/isdigit>, L<POSIX/isgraph>, L<POSIX/islower>,
 L<POSIX/isprint>, L<POSIX/ispunct>, L<POSIX/isspace>,
 L<POSIX/isupper>, L<POSIX/isxdigit>, L<POSIX/localeconv>,