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

📄 perlvar.pod

📁 source of perl for linux application,
💻 POD
📖 第 1 页 / 共 3 页
字号:
as an emergency memory pool after die()ing.  Suppose that your Perlwere compiled with -DPERL_EMERGENCY_SBRK and used Perl's malloc.Then    $^M = 'a' x (1 << 16);would allocate a 64K buffer for use in an emergency.  See theF<INSTALL> file in the Perl distribution for information on how toenable this option.  To discourage casual use of this advancedfeature, there is no L<English|English> long name for this variable.=item $OSNAME=item $^OThe name of the operating system under which this copy of Perl wasbuilt, as determined during the configuration process.  The valueis identical to C<$Config{'osname'}>.  See also L<Config> and the B<-V> command-line switch documented in L<perlrun>.=item $PERLDB=item $^PThe internal variable for debugging support.  The meanings of thevarious bits are subject to change, but currently indicate:=over 6=item 0x01Debug subroutine enter/exit.=item 0x02Line-by-line debugging.=item 0x04Switch off optimizations.=item 0x08Preserve more data for future interactive inspections.=item 0x10Keep info about source lines on which a subroutine is defined.=item 0x20Start with single-step on.=item 0x40Use subroutine address instead of name when reporting.=item 0x80Report C<goto &subroutine> as well.=item 0x100Provide informative "file" names for evals based on the place they were compiled.=item 0x200Provide informative names to anonymous subroutines based on the place theywere compiled.=backSome bits may be relevant at compile-time only, some atrun-time only.  This is a new mechanism and the details may change.=item $LAST_REGEXP_CODE_RESULT=item $^RThe result of evaluation of the last successful C<(?{ code })>regular expression assertion (see L<perlre>).  May be written to.=item $EXCEPTIONS_BEING_CAUGHT=item $^SCurrent state of the interpreter.  Undefined if parsing of the currentmodule/eval is not finished (may happen in $SIG{__DIE__} and$SIG{__WARN__} handlers).  True if inside an eval(), otherwise false.=item $BASETIME=item $^TThe time at which the program began running, in seconds since theepoch (beginning of 1970).  The values returned by the B<-M>, B<-A>,and B<-C> filetests are based on this value.=item $PERL_VERSION=item $^VThe revision, version, and subversion of the Perl interpreter, representedas a string composed of characters with those ordinals.  Thus in Perl v5.6.0it equals C<chr(5) . chr(6) . chr(0)> and will return true forC<$^V eq v5.6.0>.  Note that the characters in this string value canpotentially be in Unicode range.This 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 "No \"our\" declarations!\n" if $^V and $^V lt v5.6.0;See 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 $^WThe 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 ${^WIDE_SYSTEM_CALLS}Global flag that enables system calls made by Perl to use wide characterAPIs native to the system, if available.  This is currently only implementedon the Windows platform.This can also be enabled from the command line using the C<-C> switch.The initial value is typically C<0> for compatibility with Perl versionsearlier than 5.6, but may be automatically set to C<1> by Perl if the systemprovides a user-settable default (e.g., C<$ENV{LC_CTYPE}>).The C<bytes> pragma always overrides the effect of this flag in the currentlexical scope.  See L<bytes>.=item $EXECUTABLE_NAME=item $^XThe name that the Perl binary itself was executed as, from C's C<argv[0]>.This may not be a full pathname, nor even necessarily in your path.=item $ARGVcontains the name of the current file when reading from <>.=item @ARGVThe 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 @INCThe 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.  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;=item @_Within a subroutine the array @_ contains the parameters passed to thatsubroutine.  See L<perlsub>.=item %INCThe 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.=item %ENV=item $ENV{expr}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}The hash %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.  Ifyour system has the SA_RESTART flag it is used when signals handlers areinstalled.  This means that system calls for which restarting is supportedcontinue rather than returning when a signal arrives.  If you want yoursystem calls to be interrupted by signal delivery then do something likethis:    use POSIX ':signal_h';    my $alarm = 0;    sigaction SIGALRM, new POSIX::SigAction sub { $alarm = 1 }    	or die "Error setting SIGALRM handler: $!\n";See L<POSIX>.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 __WARN__ hook causes the ordinary printingof warnings to 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;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 __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 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 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 IndicatorsThe 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 PIPE, "/cdrom/install |";	@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>.  A fewother names are also exempt:	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.perl.com/CPAN/modules/by-module/Devel/)for more information.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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -