X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperllocale.pod;h=43ffe584ac6ffab48682055cad76eecc03a8edfe;hb=206947d2c0ace466f6b1e79f9bf44a86d72fb50d;hp=fb93792fdcf22593abbd1ea169d72505bc845fef;hpb=13a2d996abe42696bc5ca08abf08030d440c6148;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perllocale.pod b/pod/perllocale.pod index fb93792..43ffe58 100644 --- a/pod/perllocale.pod +++ b/pod/perllocale.pod @@ -310,6 +310,10 @@ locale "En_US"--and in Cshish shells (B, B) 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. @@ -381,7 +385,7 @@ with a single parameter--see L.) localeconv() takes no arguments, and returns B a hash. The keys of this hash are variable names for formatting, such as C and C. The values are the -corresponding, er, values. See L for a longer +corresponding, er, values. See L for a longer example listing the categories an implementation might be expected to provide; some provide more and others fewer. You don't need an explicit C, because localeconv() always observes the @@ -427,6 +431,31 @@ parameters as integers correctly formatted in the current locale: } print "\n"; +=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 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(langinfo ABDAY_1 YESSTR NOSTR); + + my ($abday_1, $yesstr, $nostr) = map { langinfo } qw(ABDAY_1 YESSTR NOSTR); + + print "$abday_1? [$yesstr/$nostr] "; + +In other words, in the "C" (or English) locale the above will probably +print something like: + + Sun? [yes/no] + +See L for more information. + =head1 LOCALE CATEGORIES The following subsections describe basic locale categories. Beyond these, @@ -445,7 +474,7 @@ The following collations all make sense and you may meet any of them if you "use locale". A B C D E a b c d e - A a B b C c D d D e + A a B b C c D d E e a A b B c C d D e E a b c d e A B C D E @@ -453,13 +482,13 @@ Here is a code snippet to tell what "word" characters are in the current locale, in that locale's order: use locale; - print +(sort grep /\w/, map { chr() } 0..255), "\n"; + print +(sort grep /\w/, map { chr } 0..255), "\n"; Compare this with the characters that you see and their order if you state explicitly that the locale should be ignored: no locale; - print +(sort grep /\w/, map { chr() } 0..255), "\n"; + print +(sort grep /\w/, map { chr } 0..255), "\n"; This machine-native collation (which is what you get unless S> has appeared earlier in the same block) must be used for @@ -554,26 +583,28 @@ change the character used for the decimal point--perhaps from '.' to ','. These functions aren't aware of such niceties as thousands separation and so on. (See L if you care about these things.) -Output produced by print() is B affected by the -current locale: it is independent of whether C or C is in effect, and corresponds to what you'd get from printf() -in the "C" locale. The same is true for Perl's internal conversions -between numeric and string formats: +Output produced by print() is also affected by the current locale: it +depends on whether C or C is in effect, and +corresponds to what you'd get from printf() in the "C" locale. The +same is true for Perl's internal conversions between numeric and +string formats: use POSIX qw(strtod); use locale; $n = 5/2; # Assign numeric 2.5 to $n - $a = " $n"; # Locale-independent conversion to string + $a = " $n"; # Locale-dependent conversion to string - print "half five is $n\n"; # Locale-independent output + print "half five is $n\n"; # Locale-dependent output printf "half five is %g\n", $n; # Locale-dependent output print "DECIMAL POINT IS COMMA\n" if $n == (strtod("2,5"))[0]; # Locale-dependent conversion +See also L and C. + =head2 Category LC_MONETARY: Formatting of monetary amounts The C standard defines the C category, but no function @@ -587,6 +618,8 @@ find that the information, voluminous and complex though it may be, still does not quite meet your requirements: currency formatting is a hard nut to crack. +See also L and C. + =head2 LC_TIME Output produced by POSIX::strftime(), which builds a formatted @@ -606,6 +639,9 @@ Note: C isn't needed in this example: as a function that exists only to generate locale-dependent results, strftime() always obeys the current C locale. +See also L and C..C, C..C, +C..C, and C..C. + =head2 Other categories The remaining locale category, C (possibly supplemented @@ -643,15 +679,6 @@ case-mapping table is in effect. =item * -Some systems are broken in that they allow the "C" locale to be -overridden by users. If the decimal point character in the -C category of the "C" locale is surreptitiously changed -from a dot to a comma, C produces a -string result of "123,456". Many people would interpret this as -one hundred and twenty-three thousand, four hundred and fifty-six. - -=item * - A sneaky C locale could result in the names of students with "D" grades appearing ahead of those with "A"s. @@ -687,16 +714,22 @@ the locale: =over 4 -=item B (C, C, C, C and C): +=item * + +B (C, C, C, C and C): Scalar true/false (or less/equal/greater) result is never tainted. -=item B (with C<\l>, C<\L>, C<\u> or C<\U>) +=item * + +B (with C<\l>, C<\L>, C<\u> or C<\U>) Result string containing interpolated material is tainted if C is in effect. -=item B (C): +=item * + +B (C): Scalar true/false result never tainted. @@ -709,7 +742,9 @@ expression contains C<\w> (to match an alphanumeric character), C<\W> C is in effect and the regular expression contains C<\w>, C<\W>, C<\s>, or C<\S>. -=item B (C): +=item * + +B (C): Has the same behavior as the match operator. Also, the left operand of C<=~> becomes tainted when C in effect @@ -717,20 +752,30 @@ if 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 C<\U>. -=item B (printf() and write()): +=item * + +B (printf() and write()): + +Results are never tainted because otherwise even output from print, +for example C, should be tainted if C is in +effect. -Success/failure result is never tainted. +=item * -=item B (lc(), lcfirst(), uc(), ucfirst()): +B (lc(), lcfirst(), uc(), ucfirst()): Results are tainted if C is in effect. -=item B (localeconv(), strcoll(), +=item * + +B (localeconv(), strcoll(), strftime(), strxfrm()): Results are never tainted. -=item B (isalnum(), isalpha(), isdigit(), +=item * + +B (isalnum(), isalpha(), isdigit(), isgraph(), islower(), isprint(), ispunct(), isspace(), isupper(), isxdigit()): @@ -955,12 +1000,12 @@ operating system upgrade. =head1 SEE ALSO -L, L, L, -L, L, L, -L, L, L, -L, L, L, -L, L, L, -L. +L, L, L, +L, L, L, +L, L, L, +L, L, L, +L, L, L, +L, L. =head1 HISTORY