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

📄 perlvar.pod

📁 ARM上的如果你对底层感兴趣
💻 POD
📖 第 1 页 / 共 3 页
字号:
for a convenient way to fail if the Perl interpreter is too old.

=item $DEBUGGING

=item $^D

The current value of the debugging flags.  (Mnemonic: value of B<-D>
switch.)

=item $SYSTEM_FD_MAX

=item $^F

The maximum system file descriptor, ordinarily 2.  System file
descriptors are passed to exec()ed processes, while higher file
descriptors are not.  Also, during an open(), system file descriptors are
preserved even if the open() fails.  (Ordinary file descriptors are
closed before the open() is attempted.)  Note that the close-on-exec
status of a file descriptor will be decided according to the value of
C<$^F> at the time of the open, not the time of the exec.

=item $^H

The current set of syntax checks enabled by C<use strict> and other block
scoped compiler hints.  See the documentation of C<strict> for more details.

=item $INPLACE_EDIT

=item $^I

The current value of the inplace-edit extension.  Use C<undef> to disable
inplace editing.  (Mnemonic: value of B<-i> switch.)

=item $^M

By default, running out of memory it is not trappable.  However, if
compiled for this, Perl may use the contents of C<$^M> as an emergency
pool after die()ing with this message.  Suppose that your Perl were
compiled with -DPERL_EMERGENCY_SBRK and used Perl's malloc.  Then

    $^M = 'a' x (1<<16);

would allocate a 64K buffer for use when in emergency.  See the F<INSTALL>
file for information on how to enable this option.  As a disincentive to
casual use of this advanced feature, there is no L<English> long name for
this variable.

=item $OSNAME

=item $^O

The name of the operating system under which this copy of Perl was
built, as determined during the configuration process.  The value
is identical to C<$Config{'osname'}>.

=item $PERLDB

=item $^P

The internal variable for debugging support.  Different bits mean the
following (subject to change): 

=over 6

=item 0x01

Debug subroutine enter/exit.

=item 0x02

Line-by-line debugging.

=item 0x04

Switch off optimizations.

=item 0x08

Preserve more data for future interactive inspections.

=item 0x10

Keep info about source lines on which a subroutine is defined.

=item 0x20

Start with single-step on.

=back

Note that some bits may be relevent at compile-time only, some at
run-time only. This is a new mechanism and the details may change.

=item $^R

The result of evaluation of the last successful L<perlre/C<(?{ code })>> 
regular expression assertion.  (Excluding those used as switches.)  May
be written to.

=item $^S

Current state of the interpreter.  Undefined if parsing of the current
module/eval is not finished (may happen in $SIG{__DIE__} and
$SIG{__WARN__} handlers).  True if inside an eval, otherwise false.

=item $BASETIME

=item $^T

The time at which the script began running, in seconds since the
epoch (beginning of 1970).  The values returned by the B<-M>, B<-A>,
and B<-C> filetests are
based on this value.

=item $WARNING

=item $^W

The current value of the warning switch, either TRUE or FALSE.
(Mnemonic: related to the B<-w> switch.)

=item $EXECUTABLE_NAME

=item $^X

The name that the Perl binary itself was executed as, from C's C<argv[0]>.

=item $ARGV

contains the name of the current file when reading from E<lt>E<gt>.

=item @ARGV

The array @ARGV contains the command line arguments intended for the
script.  Note that C<$#ARGV> is the generally number of arguments minus
one, because C<$ARGV[0]> is the first argument, I<NOT> the command name.  See
"C<$0>" for the command name.

=item @INC

The array @INC contains the list of places to look for Perl scripts to
be evaluated by the C<do EXPR>, C<require>, or C<use> constructs.  It
initially consists of the arguments to any B<-I> command line switches,
followed by the default Perl library, probably F</usr/local/lib/perl>,
followed by ".", to represent the current directory.  If you need to
modify this at runtime, you should use the C<use lib> pragma
to get the machine-dependent library properly loaded also:

    use lib '/mypath/libdir/';
    use SomeMod;

=item @_

Within a subroutine the array @_ contains the parameters passed to that
subroutine. See L<perlsub>.

=item %INC

The hash %INC contains entries for each filename that has
been included via C<do> or C<require>.  The key is the filename you
specified, and the value is the location of the file actually found.
The C<require> command uses this array to determine whether a given file
has already been included.

=item %ENV  $ENV{expr}

The hash %ENV contains your current environment.  Setting a
value in C<ENV> changes the environment for child processes.

=item %SIG  $SIG{expr}

The hash %SIG is used to set signal handlers for various
signals.  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 SIGQUIT

The %SIG array contains values for only the signals actually set within
the Perl script.  Here are some other examples:

    $SIG{"PIPE"} = Plumber;     # SCARY!!
    $SIG{"PIPE"} = "Plumber";   # assumes main::Plumber (not recommended)
    $SIG{"PIPE"} = \&Plumber;   # just fine; assume current Plumber
    $SIG{"PIPE"} = Plumber();   # oops, what did Plumber() return??

The one marked scary is problematic because it's a bareword, which means
sometimes it's a string representing the function, and sometimes it's
going to call the subroutine call right then and there!  Best to be sure
and quote it or take a reference to it.  *Plumber works too.  See L<perlsub>.

If your system has the sigaction() function then signal handlers are
installed using it.  This means you get reliable signal handling.  If
your system has the SA_RESTART flag it is used when signals handlers are
installed.  This means that system calls for which it is supported
continue rather than returning when a signal arrives.  If you want your
system calls to be interrupted by signal delivery then do something like
this:

    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.  The
routine indicated by C<$SIG{__WARN__}> is called when a warning message is
about to be printed.  The warning message is passed as the first
argument.  The presence of a __WARN__ hook causes the ordinary printing
of warnings to STDERR to be suppressed.  You can use this to save warnings
in 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 exception
is about to be thrown.  The error message is passed as the first
argument.  When a __DIE__ hook routine returns, the exception
processing 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 you
can die from a C<__DIE__> handler.  Similarly for C<__WARN__>.

Note that the C<$SIG{__DIE__}> hook is called even inside eval()ed
blocks/strings.  See L<perlfunc/die> and L<perlvar/$^S> for how to
circumvent this.

Note that 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
any attempt to evaluate Perl code from such a handler will probably
result in a segfault.  This means that calls which result/may-result
in parsing Perl should be used with extreme causion, like this:

    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 who
called the handler.  The second line will print backtrace and die if
Carp was available.  The third line will be executed only if Carp was
not available.

See L<perlfunc/die>, L<perlfunc/warn> and L<perlfunc/eval> for
additional info.

=back

=head2 Error Indicators

The variables L<$@>, L<$!>, L<$^E>, and L<$?> contain information about
different types of error conditions that may appear during execution of
Perl script.  The variables are shown ordered by the "distance" between
the subsystem which reported the error and the Perl process, and
correspond to errors detected by the Perl interpreter, C library,
operating system, or an external program, respectively.

To illustrate the differences between these variables, consider the 
following Perl expression:

   eval '
	 open PIPE, "/cdrom/install |";
         @res = <PIPE>;
	 close PIPE or die "bad pipe: $?, $!";
	';

After execution of this statement all 4 variables may have been set.  

$@ is set if the string to be C<eval>-ed did not compile (this may happen if 
C<open> or C<close> were imported with bad prototypes), or if Perl 
code executed during evaluation die()d (either implicitly, say, 
if C<open> was imported from module L<Fatal>, or the C<die> after 
C<close> was triggered).  In these cases the value of $@ is the compile 
error, or C<Fatal> error (which will interpolate C<$!>!), or the argument
to C<die> (which will interpolate C<$!> and C<$?>!).

When the above expression is executed, open(), C<<PIPEE<gt>>, and C<close> 
are translated to C run-time library calls.  $! is set if one of these 
calls fails.  The value is a symbolic indicator chosen by the C run-time 
library, say C<No such file or directory>.

On some systems the above C library calls are further translated 
to calls to the kernel.  The kernel may have set more verbose error 
indicator that one of the handful of standard C errors.  In such cases $^E 
contains this verbose error indicator, which may be, say, C<CDROM tray not
closed>.  On systems where C library calls are identical to system calls
$^E is a duplicate of $!.

Finally, $? may be set to non-C<0> value if the external program 
C</cdrom/install> fails.  Upper bits of the particular value may reflect 
specific error conditions encountered by this program (this is 
program-dependent), lower-bits reflect mode of failure (segfault, completion,
etc.).  Note that in contrast to $@, $!, and $^E, which are set only 
if error condition is detected, the variable $? is set on each C<wait> or
pipe C<close>, overwriting the old value.

For more details, see the individual descriptions at L<$@>, L<$!>, L<$^E>,
and L<$?>.

⌨️ 快捷键说明

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