perlvar.pod
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· POD 代码 · 共 1,720 行 · 第 1/4 页
POD
1,720 行
=item ${^UNICODE}Reflects certain Unicode settings of Perl. See L<perlrun>documentation for the C<-C> switch for more information aboutthe possible values. This variable is set during Perl startupand is thereafter read-only.=item ${^UTF8CACHE}This variable controls the state of the internal UTF-8 offset caching code.1 for on (the default), 0 for off, -1 to debug the caching code by checkingall its results against linear scans, and panicking on any discrepancy.=item ${^UTF8LOCALE}This variable indicates whether an UTF-8 locale was detected by perl atstartup. This information is used by perl when it's inadjust-utf8ness-to-locale mode (as when run with the C<-CL> command-lineswitch); see L<perlrun> for more info on this.=item $PERL_VERSION=item $^VX<$^V> X<$PERL_VERSION>The revision, version, and subversion of the Perl interpreter, representedas a C<version> object.This variable first appeared in perl 5.6.0; earlier versions of perl willsee an undefined value. Before perl 5.10.0 $^V was represented as a v-string.$^V can be used to determine whether the Perl interpreter executing ascript is in the right range of versions. (Mnemonic: use ^V for VersionControl.) Example: warn "Hashes not randomized!\n" if !$^V or $^V lt v5.8.1To convert C<$^V> into its string representation use sprintf()'sC<"%vd"> conversion: printf "version is v%vd\n", $^V; # Perl's versionSee the documentation of C<use VERSION> and C<require VERSION>for a convenient way to fail if the running Perl interpreter is too old.See also C<$]> for an older representation of the Perl version.=item $WARNING=item $^WX<$^W> X<$WARNING>The current value of the warning switch, initially true if B<-w>was used, false otherwise, but directly modifiable. (Mnemonic:related to the B<-w> switch.) See also L<warnings>.=item ${^WARNING_BITS}The current set of warning checks enabled by the C<use warnings> pragma.See the documentation of C<warnings> for more details.=item ${^WIN32_SLOPPY_STAT}If this variable is set to a true value, then stat() on Windows willnot try to open the file. This means that the link count cannot bedetermined and file attributes may be out of date if additionalhardlinks to the file exist. On the other hand, not opening the fileis considerably faster, especially for files on network drives.This variable could be set in the F<sitecustomize.pl> file toconfigure the local Perl installation to use "sloppy" stat() bydefault. See L<perlrun> for more information about sitecustomization.=item $EXECUTABLE_NAME=item $^XX<$^X> X<$EXECUTABLE_NAME>The name used to execute the current copy of Perl, from C'sC<argv[0]> or (where supported) F</proc/self/exe>.Depending on the host operating system, the value of $^X may bea relative or absolute pathname of the perl program file, or maybe the string used to invoke perl but not the pathname of theperl program file. Also, most operating systems permit invokingprograms that are not in the PATH environment variable, so thereis no guarantee that the value of $^X is in PATH. For VMS, thevalue may or may not include a version number.You usually can use the value of $^X to re-invoke an independentcopy of the same perl that is currently running, e.g., @first_run = `$^X -le "print int rand 100 for 1..100"`;But recall that not all operating systems support forking orcapturing of the output of commands, so this complex statementmay not be portable.It is not safe to use the value of $^X as a path name of a file,as some operating systems that have a mandatory suffix onexecutable files do not require use of the suffix when invokinga command. To convert the value of $^X to a path name, use thefollowing statements: # Build up a set of file names (not command names). use Config; $this_perl = $^X; if ($^O ne 'VMS') {$this_perl .= $Config{_exe} unless $this_perl =~ m/$Config{_exe}$/i;}Because many operating systems permit anyone with read access tothe Perl program file to make a copy of it, patch the copy, andthen execute the copy, the security-conscious Perl programmershould take care to invoke the installed copy of perl, not thecopy referenced by $^X. The following statements accomplishthis goal, and produce a pathname that can be invoked as acommand or referenced as a file. use Config; $secure_perl_path = $Config{perlpath}; if ($^O ne 'VMS') {$secure_perl_path .= $Config{_exe} unless $secure_perl_path =~ m/$Config{_exe}$/i;}=item ARGVX<ARGV>The special filehandle that iterates over command-line filenames inC<@ARGV>. Usually written as the null filehandle in the angle operatorC<< <> >>. Note that currently C<ARGV> only has its magical effectwithin the C<< <> >> operator; elsewhere it is just a plain filehandlecorresponding to the last file opened by C<< <> >>. In particular,passing C<\*ARGV> as a parameter to a function that expects a filehandlemay not cause your function to automatically read the contents of all thefiles in C<@ARGV>.=item $ARGVX<$ARGV>contains the name of the current file when reading from <>.=item @ARGVX<@ARGV>The array @ARGV contains the command-line arguments intended forthe script. C<$#ARGV> is generally the number of arguments minusone, because C<$ARGV[0]> is the first argument, I<not> the program'scommand name itself. See C<$0> for the command name.=item ARGVOUTX<ARGVOUT>The special filehandle that points to the currently open output filewhen doing edit-in-place processing with B<-i>. Useful when you haveto do a lot of inserting and don't want to keep modifying $_. SeeL<perlrun> for the B<-i> switch.=item @FX<@F>The array @F contains the fields of each line read in when autosplitmode is turned on. See L<perlrun> for the B<-a> switch. This arrayis package-specific, and must be declared or given a full package nameif not in package main when running under C<strict 'vars'>.=item @INCX<@INC>The array @INC contains the list of places that the C<do EXPR>,C<require>, or C<use> constructs look for their library files. Itinitially consists of the arguments to any B<-I> command-lineswitches, followed by the default Perl library, probablyF</usr/local/lib/perl>, followed by ".", to represent the currentdirectory. ("." will not be appended if taint checks are enabled, either byC<-T> or by C<-t>.) If you need to modify this at runtime, you should usethe C<use lib> pragma to get the machine-dependent library properlyloaded also: use lib '/mypath/libdir/'; use SomeMod;You can also insert hooks into the file inclusion system by putting Perlcode directly into @INC. Those hooks may be subroutine references, arrayreferences or blessed objects. See L<perlfunc/require> for details.=item @ARG=item @_X<@_> X<@ARG>Within a subroutine the array @_ contains the parameters passed to thatsubroutine. See L<perlsub>.=item %INCX<%INC>The hash %INC contains entries for each filename included via theC<do>, C<require>, or C<use> operators. The key is the filenameyou specified (with module names converted to pathnames), and thevalue is the location of the file found. The C<require>operator uses this hash to determine whether a particular file hasalready been included.If the file was loaded via a hook (e.g. a subroutine reference, seeL<perlfunc/require> for a description of these hooks), this hook isby default inserted into %INC in place of a filename. Note, however,that the hook may have set the %INC entry by itself to provide some morespecific info.=item %ENV=item $ENV{expr}X<%ENV>The hash %ENV contains your current environment. Setting avalue in C<ENV> changes the environment for any child processesyou subsequently fork() off.=item %SIG=item $SIG{expr}X<%SIG>The hash C<%SIG> contains signal handlers for signals. For example: sub handler { # 1st argument is signal name my($sig) = @_; print "Caught a SIG$sig--shutting down\n"; close(LOG); exit(0); } $SIG{'INT'} = \&handler; $SIG{'QUIT'} = \&handler; ... $SIG{'INT'} = 'DEFAULT'; # restore default action $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUITUsing a value of C<'IGNORE'> usually has the effect of ignoring thesignal, except for the C<CHLD> signal. See L<perlipc> for more aboutthis special case.Here are some other examples: $SIG{"PIPE"} = "Plumber"; # assumes main::Plumber (not recommended) $SIG{"PIPE"} = \&Plumber; # just fine; assume current Plumber $SIG{"PIPE"} = *Plumber; # somewhat esoteric $SIG{"PIPE"} = Plumber(); # oops, what did Plumber() return??Be sure not to use a bareword as the name of a signal handler,lest you inadvertently call it. If your system has the sigaction() function then signal handlers areinstalled using it. This means you get reliable signal handling.The default delivery policy of signals changed in Perl 5.8.0 from immediate (also known as "unsafe") to deferred, also known as "safe signals". See L<perlipc> for more information.Certain internal hooks can be also set using the %SIG hash. Theroutine indicated by C<$SIG{__WARN__}> is called when a warning message isabout to be printed. The warning message is passed as the firstargument. The presence of a C<__WARN__> hook causes the ordinary printingof warnings to C<STDERR> to be suppressed. You can use this to save warningsin a variable, or turn warnings into fatal errors, like this: local $SIG{__WARN__} = sub { die $_[0] }; eval $proggie;As the C<'IGNORE'> hook is not supported by C<__WARN__>, you candisable warnings using the empty subroutine: local $SIG{__WARN__} = sub {};The routine indicated by C<$SIG{__DIE__}> is called when a fatal exceptionis about to be thrown. The error message is passed as the firstargument. When a C<__DIE__> hook routine returns, the exceptionprocessing continues as it would have in the absence of the hook,unless the hook routine itself exits via a C<goto>, a loop exit, or a C<die()>.The C<__DIE__> handler is explicitly disabled during the call, so that youcan die from a C<__DIE__> handler. Similarly for C<__WARN__>.Due to an implementation glitch, the C<$SIG{__DIE__}> hook is calledeven inside an eval(). Do not use this to rewrite a pending exceptionin C<$@>, or as a bizarre substitute for overriding C<CORE::GLOBAL::die()>.This strange action at a distance may be fixed in a future releaseso that C<$SIG{__DIE__}> is only called if your program is aboutto exit, as was the original intent. Any other use is deprecated.C<__DIE__>/C<__WARN__> handlers are very special in one respect:they may be called to report (probable) errors found by the parser.In such a case the parser may be in inconsistent state, so anyattempt to evaluate Perl code from such a handler will probablyresult in a segfault. This means that warnings or errors thatresult from parsing Perl should be used with extreme caution, likethis: require Carp if defined $^S; Carp::confess("Something wrong") if defined &Carp::confess; die "Something wrong, but could not load Carp to give backtrace... To see backtrace try starting Perl with -MCarp switch";Here the first line will load Carp I<unless> it is the parser whocalled the handler. The second line will print backtrace and die ifCarp was available. The third line will be executed only if Carp wasnot available.See L<perlfunc/die>, L<perlfunc/warn>, L<perlfunc/eval>, andL<warnings> for additional information.=back=head2 Error IndicatorsX<error> X<exception>The variables C<$@>, C<$!>, C<$^E>, and C<$?> contain informationabout different types of error conditions that may appear duringexecution of a Perl program. The variables are shown ordered bythe "distance" between the subsystem which reported the error andthe Perl process. They correspond to errors detected by the Perlinterpreter, C library, operating system, or an external program,respectively.To illustrate the differences between these variables, consider the following Perl expression, which uses a single-quoted string: eval q{ open my $pipe, "/cdrom/install |" or die $!; my @res = <$pipe>; close $pipe or die "bad pipe: $?, $!"; };After execution of this statement all 4 variables may have been set. C<$@> is set if the string to be C<eval>-ed did not compile (thismay happen if C<open> or C<close> were imported with bad prototypes),or if Perl code executed during evaluation die()d . In these casesthe value of $@ is the compile error, or the argument to C<die>(which will interpolate C<$!> and C<$?>). (See also L<Fatal>,though.)When the eval() expression above is executed, open(), C<< <PIPE> >>,and C<close> are translated to calls in the C run-time library andthence to the operating system kernel. C<$!> is set to the C library'sC<errno> if one of these calls fails. Under a few operating systems, C<$^E> may contain a more verboseerror indicator, such as in this case, "CDROM tray not closed."Systems that do not support extended error messages leave C<$^E>the same as C<$!>.Finally, C<$?> may be set to non-0 value if the external programF</cdrom/install> fails. The upper eight bits reflect specificerror conditions encountered by the program (the program's exit()value). The lower eight bits reflect mode of failure, like signaldeath and core dump information See wait(2) for details. Incontrast to C<$!> and C<$^E>, which are set only if error conditionis detected, the variable C<$?> is set on each C<wait> or pipeC<close>, overwriting the old value. This is more like C<$@>, whichon every eval() is always set on failure and cleared on success.For more details, see the individual descriptions at C<$@>, C<$!>, C<$^E>,and C<$?>.=head2 Technical Note on the Syntax of Variable NamesVariable names in Perl can have several formats. Usually, theymust begin with a letter or underscore, in which case they can bearbitrarily long (up to an internal limit of 251 characters) andmay contain letters, digits, underscores, or the special sequenceC<::> or C<'>. In this case, the part before the last C<::> orC<'> is taken to be a I<package qualifier>; see L<perlmod>.Perl variable names may also be a sequence of digits or a singlepunctuation or control character. These names are all reserved forspecial uses by Perl; for example, the all-digits names are usedto hold data captured by backreferences after a regular expressionmatch. Perl has a special syntax for the single-control-characternames: It understands C<^X> (caret C<X>) to mean the control-C<X>character. For example, the notation C<$^W> (dollar-sign caretC<W>) is the scalar variable whose name is the single charactercontrol-C<W>. This is better than typing a literal control-C<W>into your program.Finally, new in Perl 5.6, Perl variable names may be alphanumericstrings that begin with control characters (or better yet, a caret).These variables must be written in the form C<${^Foo}>; the bracesare not optional. C<${^Foo}> denotes the scalar variable whosename is a control-C<F> followed by two C<o>'s. These variables arereserved for future special uses by Perl, except for the ones thatbegin with C<^_> (control-underscore or caret-underscore). Nocontrol-character name that begins with C<^_> will acquire a specialmeaning in any future version of Perl; such names may therefore beused safely in programs. C<$^_> itself, however, I<is> reserved.Perl identifiers that begin with digits, control characters, orpunctuation characters are exempt from the effects of the C<package>declaration and are always forced to be in package C<main>; they arealso exempt from C<strict 'vars'> errors. A few other names are alsoexempt in these ways: ENV STDIN INC STDOUT ARGV STDERR ARGVOUT _ SIGIn particular, the new special C<${^_XYZ}> variables are always takento be in package C<main>, regardless of any C<package> declarationspresently in scope. =head1 BUGSDue to an unfortunate accident of Perl's implementation, C<useEnglish> imposes a considerable performance penalty on all regularexpression matches in a program, regardless of whether they occurin the scope of C<use English>. For that reason, saying C<useEnglish> in libraries is strongly discouraged. See theDevel::SawAmpersand module documentation from CPAN( http://www.cpan.org/modules/by-module/Devel/ )for more information. Writing C<use English '-no_match_vars';>avoids the performance penalty.Having to even think about the C<$^S> variable in your exceptionhandlers is simply wrong. C<$SIG{__DIE__}> as currently implementedinvites grievous and difficult to track down errors. Avoid itand use an C<END{}> or CORE::GLOBAL::die override instead.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?