Variable |
Meaning |
$ARGV |
Name of the current file when reading from . |
@ARGV |
The array containing the command line arguments of the script.
Note that $#ARGV is generally the number of arguments minus one,
since $ARGV[0] is the first argument, not the command name.
See $0 for command name. |
@INC |
The array containing the list of places to look for Perl scripts
to be evaluated by the do EXPR , require, or use
constructs. It initially consists of the arguments to any -I
command line switches, followed by the default Perl libraries, such as:
/usr/locallib/perl5/$ARCH/$VERSION
/usr/locallib/perl5
/usr/locallib/perl5/site_perl
/usr/locallib/perl5/site_perl/$ARCH
followed by ".", to represent the current directory. In order to modify
this list at run-time, use the lib module in order to get the machine
dependent library loaded:
use lib '/mypath/libdir/';
use SomeMod;
|
@F |
The array into which the input lines are split when the -a
command line switch is given. |
%INC |
The hash containing entries for teh filename of each file that
has been included via a do or require. The key is the
filename you specified, and the value is the location of the file
actually found. The require command uses this array to
determine whether a given file has already been included. |
%ENV |
The hash containing the current environment. Setting a value in
%ENV changes the enviornment for child processes. To remove
something from the enviornment use delete instead if undef.
Note that processes running as a crontab entry inherit a
partiuclarly impoverished set of environment variables. Also note that
you should set $ENV{PATH}, $ENV{SHELL}, and $ENV{IFS} if you are
running as a setuid script. |
%SIG |
The hash used to get signal handlers for various signals. Example:
sub handler { # 1st argument is signal name
local($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 only contains values for the signals actually
set within the Perl script. Here are some other examples:
$SIG(PIPE) = Plumber; # SCARY!
$SIG(PIPE) = "Plumber"; # fine, assumes main::Plumber
$SIG(PIPE) = \&Plumber; # fine, assume current Plumber
$SIG(PIPE) = Plumber(); # oops, what did Plumber() return?
The example 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 right then and there!
Best to besure and quote it or take a reference to it. Certain
internal hooks can also be set using the %SIG hash. The
routine indicated by $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. One 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 $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 teh hook, unless the hook routine itself exist via a goto,
a loop exit, or a die. The __DIE__ handler is explicitly
disabled during the call, so that you youself can then call the
real di from a __DIE__ handler (which avoids an infinite
recursive sequence; same for __WARN__).
|