⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 perllocale.pod

📁 MSYS在windows下模拟了一个类unix的终端
💻 POD
📖 第 1 页 / 共 3 页
字号:
=item *The date and day names in dates formatted by strftime() could bemanipulated to advantage by a malicious user able to subvert theC<LC_DATE> locale.  ("Look--it says I wasn't in the building onSunday.")=backSuch dangers are not peculiar to the locale system: any aspect of anapplication's environment which may be modified maliciously presentssimilar challenges.  Similarly, they are not specific to Perl: anyprogramming language that allows you to write programs that takeaccount of their environment exposes you to these issues.Perl cannot protect you from all possibilities shown in theexamples--there is no substitute for your own vigilance--but, whenC<use locale> is in effect, Perl uses the tainting mechanism (seeL<perlsec>) to mark string results that become locale-dependent, andwhich may be untrustworthy in consequence.  Here is a summary of thetainting behavior of operators and functions that may be affected bythe locale:=over 4=item  *B<Comparison operators> (C<lt>, C<le>, C<ge>, C<gt> and C<cmp>):Scalar true/false (or less/equal/greater) result is never tainted.=item  *B<Case-mapping interpolation> (with C<\l>, C<\L>, C<\u> or C<\U>)Result string containing interpolated material is tainted ifC<use locale> is in effect.=item  *B<Matching operator> (C<m//>):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 regularexpression 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 ifC<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 behavior as the match operator.  Also, the leftoperand of C<=~> becomes tainted when C<use locale> in effectif modified as a result of a substitution based on a regularexpression match involving C<\w>, C<\W>, C<\s>, or C<\S>; or ofcase-mapping with C<\l>, C<\L>,C<\u> or C<\U>.=item  *B<Output formatting functions> (printf() and write()):Results are never tainted because otherwise even output from print,for example C<print(1/7)>, should be tainted if C<use locale> is ineffect.=item  *B<Case-mapping functions> (lc(), lcfirst(), uc(), ucfirst()):Results are tainted if C<use locale> is in effect.=item  *B<POSIX locale-dependent functions> (localeconv(), strcoll(),strftime(), strxfrm()):Results are never tainted.=item  *B<POSIX character class tests> (isalnum(), isalpha(), isdigit(),isgraph(), islower(), isprint(), ispunct(), isspace(), isupper(),isxdigit()):True/false results are never tainted.=backThree examples illustrate locale-dependent tainting.The first program, which ignores its locale, won't run: a value takendirectly from the command line may not be used to name an output filewhen taint checks are enabled.        #/usr/local/bin/perl -T        # Run with taint checking        # Command line sanity check omitted...        $tainted_output_file = shift;        open(F, ">$tainted_output_file")            or warn "Open of $untainted_output_file failed: $!\n";The program can be made to run by "laundering" the tainted value througha regular expression: the second example--which still ignores localeinformation--runs, creating the file named on its command lineif it can.        #/usr/local/bin/perl -T        $tainted_output_file = shift;        $tainted_output_file =~ m%[\w/]+%;        $untainted_output_file = $&;        open(F, ">$untainted_output_file")            or warn "Open of $untainted_output_file failed: $!\n";Compare this with a similar but locale-aware program:        #/usr/local/bin/perl -T        $tainted_output_file = shift;        use locale;        $tainted_output_file =~ m%[\w/]+%;        $localized_output_file = $&;        open(F, ">$localized_output_file")            or warn "Open of $localized_output_file failed: $!\n";This third program fails to run because $& is tainted: it is the resultof a match involving C<\w> while C<use locale> is in effect.=head1 ENVIRONMENT=over 12=item PERL_BADLANGA string that can suppress Perl's warning about failed locale settingsat startup.  Failure can occur if the locale support in the operatingsystem is lacking (broken) in some way--or if you mistyped the name ofa locale when you set up your environment.  If this environmentvariable is absent, or has a value that does not evaluate to integerzero--that is, "0" or ""-- Perl will complain about locale settingfailures.B<NOTE>: PERL_BADLANG only gives you a way to hide the warning message.The message tells about some problem in your system's locale support,and you should investigate what the problem is.=backThe following environment variables are not specific to Perl: They arepart of the standardized (ISO C, XPG4, POSIX 1.c) setlocale() methodfor controlling an application's opinion on data.=over 12=item LC_ALLC<LC_ALL> is the "override-all" locale environment variable. Ifset, it overrides all the rest of the locale environment variables.=item LANGUAGEB<NOTE>: C<LANGUAGE> is a GNU extension, it affects you only if youare using the GNU libc.  This is the case if you are using e.g. Linux.If you are using "commercial" UNIXes you are most probably I<not>using GNU libc and you can ignore C<LANGUAGE>.However, in the case you are using C<LANGUAGE>: it affects thelanguage of informational, warning, and error messages output bycommands (in other words, it's like C<LC_MESSAGES>) but it has higherpriority than L<LC_ALL>.  Moreover, it's not a single value butinstead a "path" (":"-separated list) of I<languages> (not locales).See the GNU C<gettext> library documentation for more information.=item LC_CTYPEIn the absence of C<LC_ALL>, C<LC_CTYPE> chooses the character typelocale.  In the absence of both C<LC_ALL> and C<LC_CTYPE>, C<LANG>chooses the character type locale.=item LC_COLLATEIn the absence of C<LC_ALL>, C<LC_COLLATE> chooses the collation(sorting) locale.  In the absence of both C<LC_ALL> and C<LC_COLLATE>,C<LANG> chooses the collation locale.=item LC_MONETARYIn the absence of C<LC_ALL>, C<LC_MONETARY> chooses the monetaryformatting locale.  In the absence of both C<LC_ALL> and C<LC_MONETARY>,C<LANG> chooses the monetary formatting locale.=item LC_NUMERICIn the absence of C<LC_ALL>, C<LC_NUMERIC> chooses the numeric formatlocale.  In the absence of both C<LC_ALL> and C<LC_NUMERIC>, C<LANG>chooses the numeric format.=item LC_TIMEIn the absence of C<LC_ALL>, C<LC_TIME> chooses the date and timeformatting locale.  In the absence of both C<LC_ALL> and C<LC_TIME>,C<LANG> chooses the date and time formatting locale.=item LANGC<LANG> is the "catch-all" locale environment variable. If it is set, itis used as the last resort after the overall C<LC_ALL> and thecategory-specific C<LC_...>.=back=head1 NOTES=head2 Backward compatibilityVersions of Perl prior to 5.004 B<mostly> ignored locale information,generally behaving as if something similar to the C<"C"> locale werealways in force, even if the program environment suggested otherwise(see L<The setlocale function>).  By default, Perl still behaves thisway for backward compatibility.  If you want a Perl application to payattention to locale information, you B<must> use the S<C<use locale>>pragma (see L<The 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 available; that is, C<\w> did understand whatwere 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 obsoleteIn versions of Perl prior to 5.004, per-locale collation was possibleusing the C<I18N::Collate> library module.  This module is now mildlyobsolete and should be avoided in new applications.  The C<LC_COLLATE>functionality is now integrated into the Perl core language: One canuse locale-specific scalar data completely normally with C<use locale>,so there is no longer any need to juggle with the scalar references ofC<I18N::Collate>.=head2 Sort speed and memory use impactsComparing and sorting by locale is usually slower than the defaultsorting; slow-downs of two to four times have been observed.  It willalso consume more memory: once a Perl scalar variable has participatedin any string comparison or sorting operation obeying the localecollation rules, it will take 3-15 times more memory than before.  (Theexact multiplier depends on the string's contents, the operating systemand the locale.) These downsides are dictated more by the operatingsystem's implementation of the locale system than by Perl.=head2 write() and LC_NUMERICFormats are the only part of Perl that unconditionally use informationfrom a program's locale; if a program's environment specifies anLC_NUMERIC locale, it is always used to specify the decimal pointcharacter in formatted output.  Formatted output cannot be controlled byC<use locale> because the pragma is tied to the block structure of theprogram, and, for historical reasons, formats exist outside that blockstructure.=head2 Freely available locale definitionsThere is a large collection of locale definitions atC<ftp://dkuug.dk/i18n/WG15-collection>.  You should be aware that it isunsupported, and is not claimed to be fit for any purpose.  If yoursystem allows installation of arbitrary locales, you may find thedefinitions useful as they are, or as a basis for the development ofyour own locales.=head2 I18n and l10n"Internationalization" is often abbreviated as B<i18n> because its firstand last letters are separated by eighteen others.  (You may guess whythe internalin ... internaliti ... i18n tends to get abbreviated.)  Inthe same way, "localization" is often abbreviated to B<l10n>.=head2 An imperfect standardInternationalization, as defined in the C and POSIX standards, can becriticized as incomplete, ungainly, and having too large a granularity.(Locales apply to a whole process, when it would arguably be more usefulto have them apply to a single thread, window group, or whatever.)  Theyalso have a tendency, like standards groups, to divide the world intonations, when we all know that the world can equally well be dividedinto bankers, bikers, gamers, and so on.  But, for now, it's the onlystandard we've got.  This may be construed as a bug.=head1 BUGS=head2 Broken systemsIn certain systems, the operating system's locale supportis broken and cannot be fixed or used by Perl.  Such deficiencies canand will result in mysterious hangs and/or Perl core dumps when theC<use locale> is in effect.  When confronted with such a system,please report in excruciating detail to <F<perlbug@perl.org>>, andcomplain to your vendor: bug fixes may exist for these problemsin your operating system.  Sometimes such bug fixes are called anoperating system upgrade.=head1 SEE ALSOL<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>, L<POSIX/setlocale>, L<POSIX/strcoll>, L<POSIX/strftime>, L<POSIX/strtod>, L<POSIX/strxfrm>.=head1 HISTORYJarkko Hietaniemi's original F<perli18n.pod> heavily hacked by DominicDunlop, assisted by the perl5-porters.  Prose worked over a bit byTom Christiansen.Last update: Thu Jun 11 08:44:13 MDT 1998

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -