📄 perlvar.pod
字号:
=item $FORMAT_LINES_LEFT=item $-The number of lines left on the page of the currently selected outputchannel. Used with formats.(Mnemonic: lines_on_page - lines_printed.)=item @LAST_MATCH_START=item @-$-[0] is the offset of the start of the last successful match.C<$-[>I<n>C<]> is the offset of the start of the substring matched byI<n>-th subpattern, or undef if the subpattern did not match.Thus after a match against $_, $& coincides with C<substr $_, $-[0],$+[0] - $-[0]>. Similarly, C<$>I<n> coincides with C<substr $_, $-[>I<n>C<],$+[>I<n>C<] - $-[>I<n>C<]> if C<$-[>I<n>C<]> is defined, and $+ coincides withC<substr $_, $-[$#-], $+[$#-]>. One can use C<$#-> to find the lastmatched subgroup in the last successful match. Contrast withC<$#+>, the number of subgroups in the regular expression. Comparewith C<@+>.This array holds the offsets of the beginnings of the lastsuccessful submatches in the currently active dynamic scope.C<$-[0]> is the offset into the string of the beginning of theentire match. The I<n>th element of this array holds the offsetof the I<n>th submatch, so C<$+[1]> is the offset where $1begins, C<$+[2]> the offset where $2 begins, and so on.You can use C<$#-> to determine how many subgroups were in thelast successful match. Compare with the C<@+> variable.After a match against some variable $var:=over 5=item C<$`> is the same as C<substr($var, 0, $-[0])>=item C<$&> is the same as C<substr($var, $-[0], $+[0] - $-[0])>=item C<$'> is the same as C<substr($var, $+[0])>=item C<$1> is the same as C<substr($var, $-[1], $+[1] - $-[1])> =item C<$2> is the same as C<substr($var, $-[2], $+[2] - $-[2])>=item C<$3> is the same as C<substr $var, $-[3], $+[3] - $-[3])>=back=item format_name HANDLE EXPR=item $FORMAT_NAME=item $~The name of the current report format for the currently selected outputchannel. Default is the name of the filehandle. (Mnemonic: brother toC<$^>.)=item format_top_name HANDLE EXPR=item $FORMAT_TOP_NAME=item $^The name of the current top-of-page format for the currently selectedoutput channel. Default is the name of the filehandle with _TOPappended. (Mnemonic: points to top of page.)=item format_line_break_characters HANDLE EXPR=item $FORMAT_LINE_BREAK_CHARACTERS=item $:The current set of characters after which a string may be broken tofill continuation fields (starting with ^) in a format. Default isS<" \n-">, to break on whitespace or hyphens. (Mnemonic: a "colon" inpoetry is a part of a line.)=item format_formfeed HANDLE EXPR=item $FORMAT_FORMFEED=item $^LWhat formats output as a form feed. Default is \f.=item $ACCUMULATOR=item $^AThe current value of the write() accumulator for format() lines. A formatcontains formline() calls that put their result into C<$^A>. Aftercalling its format, write() prints out the contents of C<$^A> and empties.So you never really see the contents of C<$^A> unless you callformline() yourself and then look at it. See L<perlform> andL<perlfunc/formline()>.=item $CHILD_ERROR=item $?The status returned by the last pipe close, backtick (C<``>) command,successful call to wait() or waitpid(), or from the system()operator. This is just the 16-bit status word returned by thewait() system call (or else is made up to look like it). Thus, theexit value of the subprocess is really (C<<< $? >> 8 >>>), andC<$? & 127> gives which signal, if any, the process died from, andC<$? & 128> reports whether there was a core dump. (Mnemonic:similar to B<sh> and B<ksh>.)Additionally, if the C<h_errno> variable is supported in C, its valueis returned via $? if any C<gethost*()> function fails.If you have installed a signal handler for C<SIGCHLD>, thevalue of C<$?> will usually be wrong outside that handler.Inside an C<END> subroutine C<$?> contains the value that is going to begiven to C<exit()>. You can modify C<$?> in an C<END> subroutine tochange the exit status of your program. For example: END { $? = 1 if $? == 255; # die would make it 255 } Under VMS, the pragma C<use vmsish 'status'> makes C<$?> reflect theactual VMS exit status, instead of the default emulation of POSIXstatus.Also see L<Error Indicators>.=item $OS_ERROR=item $ERRNO=item $!If used numerically, yields the current value of the C C<errno>variable, with all the usual caveats. (This means that you shouldn'tdepend on the value of C<$!> to be anything in particular unlessyou've gotten a specific error return indicating a system error.)If used an a string, yields the corresponding system error string.You can assign a number to C<$!> to set I<errno> if, for instance,you want C<"$!"> to return the string for error I<n>, or you wantto set the exit value for the die() operator. (Mnemonic: What justwent bang?)Also see L<Error Indicators>.=item $EXTENDED_OS_ERROR=item $^EError information specific to the current operating system. Atthe moment, this differs from C<$!> under only VMS, OS/2, and Win32(and for MacPerl). On all other platforms, C<$^E> is always justthe same as C<$!>.Under VMS, C<$^E> provides the VMS status value from the lastsystem error. This is more specific information about the lastsystem error than that provided by C<$!>. This is particularlyimportant when C<$!> is set to B<EVMSERR>.Under OS/2, C<$^E> is set to the error code of the last call toOS/2 API either via CRT, or directly from perl.Under Win32, C<$^E> always returns the last error informationreported by the Win32 call C<GetLastError()> which describesthe last error from within the Win32 API. Most Win32-specificcode will report errors via C<$^E>. ANSI C and Unix-like callsset C<errno> and so most portable Perl code will report errorsvia C<$!>. Caveats mentioned in the description of C<$!> generally apply toC<$^E>, also. (Mnemonic: Extra error explanation.)Also see L<Error Indicators>.=item $EVAL_ERROR=item $@The Perl syntax error message from the last eval() operator. If null, thelast eval() parsed and executed correctly (although the operations youinvoked may have failed in the normal fashion). (Mnemonic: Where wasthe syntax error "at"?)Warning messages are not collected in this variable. You can,however, set up a routine to process warnings by setting C<$SIG{__WARN__}>as described below.Also see L<Error Indicators>.=item $PROCESS_ID=item $PID=item $$The process number of the Perl running this script. You shouldconsider this variable read-only, although it will be alteredacross fork() calls. (Mnemonic: same as shells.)=item $REAL_USER_ID=item $UID=item $<The real uid of this process. (Mnemonic: it's the uid you came I<from>,if you're running setuid.)=item $EFFECTIVE_USER_ID=item $EUID=item $>The effective uid of this process. Example: $< = $>; # set real to effective uid ($<,$>) = ($>,$<); # swap real and effective uid(Mnemonic: it's the uid you went I<to>, if you're running setuid.)C<< $< >> and C<< $> >> can be swapped only on machinessupporting setreuid().=item $REAL_GROUP_ID=item $GID=item $(The real gid of this process. If you are on a machine that supportsmembership in multiple groups simultaneously, gives a space separatedlist of groups you are in. The first number is the one returned bygetgid(), and the subsequent ones by getgroups(), one of which may bethe same as the first number.However, a value assigned to C<$(> must be a single number used toset the real gid. So the value given by C<$(> should I<not> be assignedback to C<$(> without being forced numeric, such as by adding zero.(Mnemonic: parentheses are used to I<group> things. The real gid is thegroup you I<left>, if you're running setgid.)=item $EFFECTIVE_GROUP_ID=item $EGID=item $)The effective gid of this process. If you are on a machine thatsupports membership in multiple groups simultaneously, gives a spaceseparated list of groups you are in. The first number is the onereturned by getegid(), and the subsequent ones by getgroups(), one ofwhich may be the same as the first number.Similarly, a value assigned to C<$)> must also be a space-separatedlist of numbers. The first number sets the effective gid, andthe rest (if any) are passed to setgroups(). To get the effect of anempty list for setgroups(), just repeat the new effective gid; that is,to force an effective gid of 5 and an effectively empty setgroups()list, say C< $) = "5 5" >.(Mnemonic: parentheses are used to I<group> things. The effective gidis the group that's I<right> for you, if you're running setgid.)C<< $< >>, C<< $> >>, C<$(> and C<$)> can be set only onmachines that support the corresponding I<set[re][ug]id()> routine. C<$(>and C<$)> can be swapped only on machines supporting setregid().=item $PROGRAM_NAME=item $0Contains the name of the program being executed. On some operatingsystems assigning to C<$0> modifies the argument area that the B<ps>program sees. This is more useful as a way of indicating the currentprogram state than it is for hiding the program you're running.(Mnemonic: same as B<sh> and B<ksh>.)Note for BSD users: setting C<$0> does not completely remove "perl"from the ps(1) output. For example, setting C<$0> to C<"foobar"> willresult in C<"perl: foobar (perl)">. This is an operating systemfeature.=item $[The index of the first element in an array, and of the first characterin a substring. Default is 0, but you could theoretically set itto 1 to make Perl behave more like B<awk> (or Fortran) whensubscripting and when evaluating the index() and substr() functions.(Mnemonic: [ begins subscripts.)As of release 5 of Perl, assignment to C<$[> is treated as a compilerdirective, and cannot influence the behavior of any other file.Its use is highly discouraged.=item $]The version + patchlevel / 1000 of the Perl interpreter. This variablecan be used to determine whether the Perl interpreter executing ascript is in the right range of versions. (Mnemonic: Is this versionof perl in the right bracket?) Example: warn "No checksumming!\n" if $] < 3.019;See also the documentation of C<use VERSION> and C<require VERSION>for a convenient way to fail if the running Perl interpreter is too old.The use of this variable is deprecated. The floating point representationcan sometimes lead to inaccurate numeric comparisons. See C<$^V> for amore modern representation of the Perl version that allows accurate stringcomparisons.=item $COMPILING=item $^CThe current value of the flag associated with the B<-c> switch.Mainly of use with B<-MO=...> to allow code to alter its behaviorwhen being compiled, such as for example to AUTOLOAD at compiletime rather than normal, deferred loading. See L<perlcc>. SettingC<$^C = 1> is similar to calling C<B::minus_c>.=item $DEBUGGING=item $^DThe current value of the debugging flags. (Mnemonic: value of B<-D>switch.)=item $SYSTEM_FD_MAX=item $^FThe maximum system file descriptor, ordinarily 2. System filedescriptors are passed to exec()ed processes, while higher filedescriptors are not. Also, during an open(), system file descriptors arepreserved even if the open() fails. (Ordinary file descriptors areclosed before the open() is attempted.) The close-on-execstatus of a file descriptor will be decided according to the value ofC<$^F> when the corresponding file, pipe, or socket was opened, not thetime of the exec().=item $^HWARNING: This variable is strictly for internal use only. Its availability,behavior, and contents are subject to change without notice.This variable contains compile-time hints for the Perl interpreter. At theend of compilation of a BLOCK the value of this variable is restored to thevalue when the interpreter started to compile the BLOCK.When perl begins to parse any block construct that provides a lexical scope(e.g., eval body, required file, subroutine body, loop body, or conditionalblock), the existing value of $^H is saved, but its value is left unchanged.When the compilation of the block is completed, it regains the saved value.Between the points where its value is saved and restored, code thatexecutes within BEGIN blocks is free to change the value of $^H.This behavior provides the semantic of lexical scoping, and is used in,for instance, the C<use strict> pragma.The contents should be an integer; different bits of it are used fordifferent pragmatic flags. Here's an example: sub add_100 { $^H |= 0x100 } sub foo { BEGIN { add_100() } bar->baz($boon); }Consider what happens during execution of the BEGIN block. At this pointthe BEGIN block has already been compiled, but the body of foo() is stillbeing compiled. The new value of $^H will therefore be visible only whilethe body of foo() is being compiled.Substitution of the above BEGIN block with: BEGIN { require strict; strict->import('vars') }demonstrates how C<use strict 'vars'> is implemented. Here's a conditionalversion of the same lexical pragma: BEGIN { require strict; strict->import('vars') if $condition }=item %^HWARNING: This variable is strictly for internal use only. Its availability,behavior, and contents are subject to change without notice.The %^H hash provides the same scoping semantic as $^H. This makes ituseful for implementation of lexically scoped pragmas.=item $INPLACE_EDIT=item $^IThe current value of the inplace-edit extension. Use C<undef> to disableinplace editing. (Mnemonic: value of B<-i> switch.)=item $^MBy default, running out of memory is an untrappable, fatal error.However, if suitably built, Perl can use the contents of C<$^M>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -