1N/A=head1 NAME
1N/A
1N/Aperlvar - Perl predefined variables
1N/A
1N/A=head1 DESCRIPTION
1N/A
1N/A=head2 Predefined Names
1N/A
1N/AThe following names have special meaning to Perl. Most
1N/Apunctuation names have reasonable mnemonics, or analogs in the
1N/Ashells. Nevertheless, if you wish to use long variable names,
1N/Ayou need only say
1N/A
1N/A use English;
1N/A
1N/Aat the top of your program. This aliases all the short names to the long
1N/Anames in the current package. Some even have medium names, generally
1N/Aborrowed from B<awk>. In general, it's best to use the
1N/A
1N/A use English '-no_match_vars';
1N/A
1N/Ainvocation if you don't need $PREMATCH, $MATCH, or $POSTMATCH, as it avoids
1N/Aa certain performance hit with the use of regular expressions. See
1N/AL<English>.
1N/A
1N/AVariables that depend on the currently selected filehandle may be set by
1N/Acalling an appropriate object method on the IO::Handle object, although
1N/Athis is less efficient than using the regular built-in variables. (Summary
1N/Alines below for this contain the word HANDLE.) First you must say
1N/A
1N/A use IO::Handle;
1N/A
1N/Aafter which you may use either
1N/A
1N/A method HANDLE EXPR
1N/A
1N/Aor more safely,
1N/A
1N/A HANDLE->method(EXPR)
1N/A
1N/AEach method returns the old value of the IO::Handle attribute.
1N/AThe methods each take an optional EXPR, which, if supplied, specifies the
1N/Anew value for the IO::Handle attribute in question. If not supplied,
1N/Amost methods do nothing to the current value--except for
1N/Aautoflush(), which will assume a 1 for you, just to be different.
1N/A
1N/ABecause loading in the IO::Handle class is an expensive operation, you should
1N/Alearn how to use the regular built-in variables.
1N/A
1N/AA few of these variables are considered "read-only". This means that if
1N/Ayou try to assign to this variable, either directly or indirectly through
1N/Aa reference, you'll raise a run-time exception.
1N/A
1N/AYou should be very careful when modifying the default values of most
1N/Aspecial variables described in this document. In most cases you want
1N/Ato localize these variables before changing them, since if you don't,
1N/Athe change may affect other modules which rely on the default values
1N/Aof the special variables that you have changed. This is one of the
1N/Acorrect ways to read the whole file at once:
1N/A
1N/A open my $fh, "foo" or die $!;
1N/A local $/; # enable localized slurp mode
1N/A my $content = <$fh>;
1N/A close $fh;
1N/A
1N/ABut the following code is quite bad:
1N/A
1N/A open my $fh, "foo" or die $!;
1N/A undef $/; # enable slurp mode
1N/A my $content = <$fh>;
1N/A close $fh;
1N/A
1N/Asince some other module, may want to read data from some file in the
1N/Adefault "line mode", so if the code we have just presented has been
1N/Aexecuted, the global value of C<$/> is now changed for any other code
1N/Arunning inside the same Perl interpreter.
1N/A
1N/AUsually when a variable is localized you want to make sure that this
1N/Achange affects the shortest scope possible. So unless you are already
1N/Ainside some short C<{}> block, you should create one yourself. For
1N/Aexample:
1N/A
1N/A my $content = '';
1N/A open my $fh, "foo" or die $!;
1N/A {
1N/A local $/;
1N/A $content = <$fh>;
1N/A }
1N/A close $fh;
1N/A
1N/AHere is an example of how your own code can go broken:
1N/A
1N/A for (1..5){
1N/A nasty_break();
1N/A print "$_ ";
1N/A }
1N/A sub nasty_break {
1N/A $_ = 5;
1N/A # do something with $_
1N/A }
1N/A
1N/AYou probably expect this code to print:
1N/A
1N/A 1 2 3 4 5
1N/A
1N/Abut instead you get:
1N/A
1N/A 5 5 5 5 5
1N/A
1N/AWhy? Because nasty_break() modifies C<$_> without localizing it
1N/Afirst. The fix is to add local():
1N/A
1N/A local $_ = 5;
1N/A
1N/AIt's easy to notice the problem in such a short example, but in more
1N/Acomplicated code you are looking for trouble if you don't localize
1N/Achanges to the special variables.
1N/A
1N/AThe following list is ordered by scalar variables first, then the
1N/Aarrays, then the hashes.
1N/A
1N/A=over 8
1N/A
1N/A=item $ARG
1N/A
1N/A=item $_
1N/A
1N/AThe default input and pattern-searching space. The following pairs are
1N/Aequivalent:
1N/A
1N/A while (<>) {...} # equivalent only in while!
1N/A while (defined($_ = <>)) {...}
1N/A
1N/A /^Subject:/
1N/A $_ =~ /^Subject:/
1N/A
1N/A tr/a-z/A-Z/
1N/A $_ =~ tr/a-z/A-Z/
1N/A
1N/A chomp
1N/A chomp($_)
1N/A
1N/AHere are the places where Perl will assume $_ even if you
1N/Adon't use it:
1N/A
1N/A=over 3
1N/A
1N/A=item *
1N/A
1N/AVarious unary functions, including functions like ord() and int(), as well
1N/Aas the all file tests (C<-f>, C<-d>) except for C<-t>, which defaults to
1N/ASTDIN.
1N/A
1N/A=item *
1N/A
1N/AVarious list functions like print() and unlink().
1N/A
1N/A=item *
1N/A
1N/AThe pattern matching operations C<m//>, C<s///>, and C<tr///> when used
1N/Awithout an C<=~> operator.
1N/A
1N/A=item *
1N/A
1N/AThe default iterator variable in a C<foreach> loop if no other
1N/Avariable is supplied.
1N/A
1N/A=item *
1N/A
1N/AThe implicit iterator variable in the grep() and map() functions.
1N/A
1N/A=item *
1N/A
1N/AThe default place to put an input record when a C<< <FH> >>
1N/Aoperation's result is tested by itself as the sole criterion of a C<while>
1N/Atest. Outside a C<while> test, this will not happen.
1N/A
1N/A=back
1N/A
1N/A(Mnemonic: underline is understood in certain operations.)
1N/A
1N/A=back
1N/A
1N/A=over 8
1N/A
1N/A=item $a
1N/A
1N/A=item $b
1N/A
1N/ASpecial package variables when using sort(), see L<perlfunc/sort>.
1N/ABecause of this specialness $a and $b don't need to be declared
1N/A(using use vars, or our()) even when using the C<strict 'vars'> pragma.
1N/ADon't lexicalize them with C<my $a> or C<my $b> if you want to be
1N/Aable to use them in the sort() comparison block or function.
1N/A
1N/A=back
1N/A
1N/A=over 8
1N/A
1N/A=item $<I<digits>>
1N/A
1N/AContains the subpattern from the corresponding set of capturing
1N/Aparentheses from the last pattern match, not counting patterns
1N/Amatched in nested blocks that have been exited already. (Mnemonic:
1N/Alike \digits.) These variables are all read-only and dynamically
1N/Ascoped to the current BLOCK.
1N/A
1N/A=item $MATCH
1N/A
1N/A=item $&
1N/A
1N/AThe string matched by the last successful pattern match (not counting
1N/Aany matches hidden within a BLOCK or eval() enclosed by the current
1N/ABLOCK). (Mnemonic: like & in some editors.) This variable is read-only
1N/Aand dynamically scoped to the current BLOCK.
1N/A
1N/AThe use of this variable anywhere in a program imposes a considerable
1N/Aperformance penalty on all regular expression matches. See L</BUGS>.
1N/A
1N/A=item $PREMATCH
1N/A
1N/A=item $`
1N/A
1N/AThe string preceding whatever was matched by the last successful
1N/Apattern match (not counting any matches hidden within a BLOCK or eval
1N/Aenclosed by the current BLOCK). (Mnemonic: C<`> often precedes a quoted
1N/Astring.) This variable is read-only.
1N/A
1N/AThe use of this variable anywhere in a program imposes a considerable
1N/Aperformance penalty on all regular expression matches. See L</BUGS>.
1N/A
1N/A=item $POSTMATCH
1N/A
1N/A=item $'
1N/A
1N/AThe string following whatever was matched by the last successful
1N/Apattern match (not counting any matches hidden within a BLOCK or eval()
1N/Aenclosed by the current BLOCK). (Mnemonic: C<'> often follows a quoted
1N/Astring.) Example:
1N/A
1N/A local $_ = 'abcdefghi';
1N/A /def/;
1N/A print "$`:$&:$'\n"; # prints abc:def:ghi
1N/A
1N/AThis variable is read-only and dynamically scoped to the current BLOCK.
1N/A
1N/AThe use of this variable anywhere in a program imposes a considerable
1N/Aperformance penalty on all regular expression matches. See L</BUGS>.
1N/A
1N/A=item $LAST_PAREN_MATCH
1N/A
1N/A=item $+
1N/A
1N/AThe text matched by the last bracket of the last successful search pattern.
1N/AThis is useful if you don't know which one of a set of alternative patterns
1N/Amatched. For example:
1N/A
1N/A /Version: (.*)|Revision: (.*)/ && ($rev = $+);
1N/A
1N/A(Mnemonic: be positive and forward looking.)
1N/AThis variable is read-only and dynamically scoped to the current BLOCK.
1N/A
1N/A=item $^N
1N/A
1N/AThe text matched by the used group most-recently closed (i.e. the group
1N/Awith the rightmost closing parenthesis) of the last successful search
1N/Apattern. (Mnemonic: the (possibly) Nested parenthesis that most
1N/Arecently closed.)
1N/A
1N/AThis is primarily used inside C<(?{...})> blocks for examining text
1N/Arecently matched. For example, to effectively capture text to a variable
1N/A(in addition to C<$1>, C<$2>, etc.), replace C<(...)> with
1N/A
1N/A (?:(...)(?{ $var = $^N }))
1N/A
1N/ABy setting and then using C<$var> in this way relieves you from having to
1N/Aworry about exactly which numbered set of parentheses they are.
1N/A
1N/AThis variable is dynamically scoped to the current BLOCK.
1N/A
1N/A=item @LAST_MATCH_END
1N/A
1N/A=item @+
1N/A
1N/AThis array holds the offsets of the ends of the last successful
1N/Asubmatches in the currently active dynamic scope. C<$+[0]> is
1N/Athe offset into the string of the end of the entire match. This
1N/Ais the same value as what the C<pos> function returns when called
1N/Aon the variable that was matched against. The I<n>th element
1N/Aof this array holds the offset of the I<n>th submatch, so
1N/AC<$+[1]> is the offset past where $1 ends, C<$+[2]> the offset
1N/Apast where $2 ends, and so on. You can use C<$#+> to determine
1N/Ahow many subgroups were in the last successful match. See the
1N/Aexamples given for the C<@-> variable.
1N/A
1N/A=item $*
1N/A
1N/ASet to a non-zero integer value to do multi-line matching within a
1N/Astring, 0 (or undefined) to tell Perl that it can assume that strings
1N/Acontain a single line, for the purpose of optimizing pattern matches.
1N/APattern matches on strings containing multiple newlines can produce
1N/Aconfusing results when C<$*> is 0 or undefined. Default is undefined.
1N/A(Mnemonic: * matches multiple things.) This variable influences the
1N/Ainterpretation of only C<^> and C<$>. A literal newline can be searched
1N/Afor even when C<$* == 0>.
1N/A
1N/AUse of C<$*> is deprecated in modern Perl, supplanted by
1N/Athe C</s> and C</m> modifiers on pattern matching.
1N/A
1N/AAssigning a non-numerical value to C<$*> triggers a warning (and makes
1N/AC<$*> act if C<$* == 0>), while assigning a numerical value to C<$*>
1N/Amakes that an implicit C<int> is applied on the value.
1N/A
1N/A=item HANDLE->input_line_number(EXPR)
1N/A
1N/A=item $INPUT_LINE_NUMBER
1N/A
1N/A=item $NR
1N/A
1N/A=item $.
1N/A
1N/ACurrent line number for the last filehandle accessed.
1N/A
1N/AEach filehandle in Perl counts the number of lines that have been read
1N/Afrom it. (Depending on the value of C<$/>, Perl's idea of what
1N/Aconstitutes a line may not match yours.) When a line is read from a
1N/Afilehandle (via readline() or C<< <> >>), or when tell() or seek() is
1N/Acalled on it, C<$.> becomes an alias to the line counter for that
1N/Afilehandle.
1N/A
1N/AYou can adjust the counter by assigning to C<$.>, but this will not
1N/Aactually move the seek pointer. I<Localizing C<$.> will not localize
1N/Athe filehandle's line count>. Instead, it will localize perl's notion
1N/Aof which filehandle C<$.> is currently aliased to.
1N/A
1N/AC<$.> is reset when the filehandle is closed, but B<not> when an open
1N/Afilehandle is reopened without an intervening close(). For more
1N/Adetails, see L<perlop/"IE<sol>O Operators">. Because C<< <> >> never does
1N/Aan explicit close, line numbers increase across ARGV files (but see
1N/Aexamples in L<perlfunc/eof>).
1N/A
1N/AYou can also use C<< HANDLE->input_line_number(EXPR) >> to access the
1N/Aline counter for a given filehandle without having to worry about
1N/Awhich handle you last accessed.
1N/A
1N/A(Mnemonic: many programs use "." to mean the current line number.)
1N/A
1N/A=item IO::Handle->input_record_separator(EXPR)
1N/A
1N/A=item $INPUT_RECORD_SEPARATOR
1N/A
1N/A=item $RS
1N/A
1N/A=item $/
1N/A
1N/AThe input record separator, newline by default. This
1N/Ainfluences Perl's idea of what a "line" is. Works like B<awk>'s RS
1N/Avariable, including treating empty lines as a terminator if set to
1N/Athe null string. (An empty line cannot contain any spaces
1N/Aor tabs.) You may set it to a multi-character string to match a
1N/Amulti-character terminator, or to C<undef> to read through the end
1N/Aof file. Setting it to C<"\n\n"> means something slightly
1N/Adifferent than setting to C<"">, if the file contains consecutive
1N/Aempty lines. Setting to C<""> will treat two or more consecutive
1N/Aempty lines as a single empty line. Setting to C<"\n\n"> will
1N/Ablindly assume that the next input character belongs to the next
1N/Aparagraph, even if it's a newline. (Mnemonic: / delimits
1N/Aline boundaries when quoting poetry.)
1N/A
1N/A local $/; # enable "slurp" mode
1N/A local $_ = <FH>; # whole file now here
1N/A s/\n[ \t]+/ /g;
1N/A
1N/ARemember: the value of C<$/> is a string, not a regex. B<awk> has to be
1N/Abetter for something. :-)
1N/A
1N/ASetting C<$/> to a reference to an integer, scalar containing an integer, or
1N/Ascalar that's convertible to an integer will attempt to read records
1N/Ainstead of lines, with the maximum record size being the referenced
1N/Ainteger. So this:
1N/A
1N/A local $/ = \32768; # or \"32768", or \$var_containing_32768
1N/A open my $fh, $myfile or die $!;
1N/A local $_ = <$fh>;
1N/A
1N/Awill read a record of no more than 32768 bytes from FILE. If you're
1N/Anot reading from a record-oriented file (or your OS doesn't have
1N/Arecord-oriented files), then you'll likely get a full chunk of data
1N/Awith every read. If a record is larger than the record size you've
1N/Aset, you'll get the record back in pieces.
1N/A
1N/AOn VMS, record reads are done with the equivalent of C<sysread>,
1N/Aso it's best not to mix record and non-record reads on the same
1N/Afile. (This is unlikely to be a problem, because any file you'd
1N/Awant to read in record mode is probably unusable in line mode.)
1N/ANon-VMS systems do normal I/O, so it's safe to mix record and
1N/Anon-record reads of a file.
1N/A
1N/ASee also L<perlport/"Newlines">. Also see C<$.>.
1N/A
1N/A=item HANDLE->autoflush(EXPR)
1N/A
1N/A=item $OUTPUT_AUTOFLUSH
1N/A
1N/A=item $|
1N/A
1N/AIf set to nonzero, forces a flush right away and after every write
1N/Aor print on the currently selected output channel. Default is 0
1N/A(regardless of whether the channel is really buffered by the
1N/Asystem or not; C<$|> tells you only whether you've asked Perl
1N/Aexplicitly to flush after each write). STDOUT will
1N/Atypically be line buffered if output is to the terminal and block
1N/Abuffered otherwise. Setting this variable is useful primarily when
1N/Ayou are outputting to a pipe or socket, such as when you are running
1N/Aa Perl program under B<rsh> and want to see the output as it's
1N/Ahappening. This has no effect on input buffering. See L<perlfunc/getc>
1N/Afor that. (Mnemonic: when you want your pipes to be piping hot.)
1N/A
1N/A=item IO::Handle->output_field_separator EXPR
1N/A
1N/A=item $OUTPUT_FIELD_SEPARATOR
1N/A
1N/A=item $OFS
1N/A
1N/A=item $,
1N/A
1N/AThe output field separator for the print operator. Ordinarily the
1N/Aprint operator simply prints out its arguments without further
1N/Aadornment. To get behavior more like B<awk>, set this variable as
1N/Ayou would set B<awk>'s OFS variable to specify what is printed
1N/Abetween fields. (Mnemonic: what is printed when there is a "," in
1N/Ayour print statement.)
1N/A
1N/A=item IO::Handle->output_record_separator EXPR
1N/A
1N/A=item $OUTPUT_RECORD_SEPARATOR
1N/A
1N/A=item $ORS
1N/A
1N/A=item $\
1N/A
1N/AThe output record separator for the print operator. Ordinarily the
1N/Aprint operator simply prints out its arguments as is, with no
1N/Atrailing newline or other end-of-record string added. To get
1N/Abehavior more like B<awk>, set this variable as you would set
1N/AB<awk>'s ORS variable to specify what is printed at the end of the
1N/Aprint. (Mnemonic: you set C<$\> instead of adding "\n" at the
1N/Aend of the print. Also, it's just like C<$/>, but it's what you
1N/Aget "back" from Perl.)
1N/A
1N/A=item $LIST_SEPARATOR
1N/A
1N/A=item $"
1N/A
1N/AThis is like C<$,> except that it applies to array and slice values
1N/Ainterpolated into a double-quoted string (or similar interpreted
1N/Astring). Default is a space. (Mnemonic: obvious, I think.)
1N/A
1N/A=item $SUBSCRIPT_SEPARATOR
1N/A
1N/A=item $SUBSEP
1N/A
1N/A=item $;
1N/A
1N/AThe subscript separator for multidimensional array emulation. If you
1N/Arefer to a hash element as
1N/A
1N/A $foo{$a,$b,$c}
1N/A
1N/Ait really means
1N/A
1N/A $foo{join($;, $a, $b, $c)}
1N/A
1N/ABut don't put
1N/A
1N/A @foo{$a,$b,$c} # a slice--note the @
1N/A
1N/Awhich means
1N/A
1N/A ($foo{$a},$foo{$b},$foo{$c})
1N/A
1N/ADefault is "\034", the same as SUBSEP in B<awk>. If your
1N/Akeys contain binary data there might not be any safe value for C<$;>.
1N/A(Mnemonic: comma (the syntactic subscript separator) is a
1N/Asemi-semicolon. Yeah, I know, it's pretty lame, but C<$,> is already
1N/Ataken for something more important.)
1N/A
1N/AConsider using "real" multidimensional arrays as described
1N/Ain L<perllol>.
1N/A
1N/A=item $#
1N/A
1N/AThe output format for printed numbers. This variable is a half-hearted
1N/Aattempt to emulate B<awk>'s OFMT variable. There are times, however,
1N/Awhen B<awk> and Perl have differing notions of what counts as
1N/Anumeric. The initial value is "%.I<n>g", where I<n> is the value
1N/Aof the macro DBL_DIG from your system's F<float.h>. This is different from
1N/AB<awk>'s default OFMT setting of "%.6g", so you need to set C<$#>
1N/Aexplicitly to get B<awk>'s value. (Mnemonic: # is the number sign.)
1N/A
1N/AUse of C<$#> is deprecated.
1N/A
1N/A=item HANDLE->format_page_number(EXPR)
1N/A
1N/A=item $FORMAT_PAGE_NUMBER
1N/A
1N/A=item $%
1N/A
1N/AThe current page number of the currently selected output channel.
1N/AUsed with formats.
1N/A(Mnemonic: % is page number in B<nroff>.)
1N/A
1N/A=item HANDLE->format_lines_per_page(EXPR)
1N/A
1N/A=item $FORMAT_LINES_PER_PAGE
1N/A
1N/A=item $=
1N/A
1N/AThe current page length (printable lines) of the currently selected
1N/Aoutput channel. Default is 60.
1N/AUsed with formats.
1N/A(Mnemonic: = has horizontal lines.)
1N/A
1N/A=item HANDLE->format_lines_left(EXPR)
1N/A
1N/A=item $FORMAT_LINES_LEFT
1N/A
1N/A=item $-
1N/A
1N/AThe number of lines left on the page of the currently selected output
1N/Achannel.
1N/AUsed with formats.
1N/A(Mnemonic: lines_on_page - lines_printed.)
1N/A
1N/A=item @LAST_MATCH_START
1N/A
1N/A=item @-
1N/A
1N/A$-[0] is the offset of the start of the last successful match.
1N/AC<$-[>I<n>C<]> is the offset of the start of the substring matched by
1N/AI<n>-th subpattern, or undef if the subpattern did not match.
1N/A
1N/AThus after a match against $_, $& coincides with C<substr $_, $-[0],
1N/A$+[0] - $-[0]>. Similarly, C<$>I<n> coincides with C<substr $_, $-[>I<n>C<],
1N/A$+[>I<n>C<] - $-[>I<n>C<]> if C<$-[>I<n>C<]> is defined, and $+ coincides with
1N/AC<substr $_, $-[$#-], $+[$#-]>. One can use C<$#-> to find the last
1N/Amatched subgroup in the last successful match. Contrast with
1N/AC<$#+>, the number of subgroups in the regular expression. Compare
1N/Awith C<@+>.
1N/A
1N/AThis array holds the offsets of the beginnings of the last
1N/Asuccessful submatches in the currently active dynamic scope.
1N/AC<$-[0]> is the offset into the string of the beginning of the
1N/Aentire match. The I<n>th element of this array holds the offset
1N/Aof the I<n>th submatch, so C<$-[1]> is the offset where $1
1N/Abegins, C<$-[2]> the offset where $2 begins, and so on.
1N/A
1N/AAfter a match against some variable $var:
1N/A
1N/A=over 5
1N/A
1N/A=item C<$`> is the same as C<substr($var, 0, $-[0])>
1N/A
1N/A=item C<$&> is the same as C<substr($var, $-[0], $+[0] - $-[0])>
1N/A
1N/A=item C<$'> is the same as C<substr($var, $+[0])>
1N/A
1N/A=item C<$1> is the same as C<substr($var, $-[1], $+[1] - $-[1])>
1N/A
1N/A=item C<$2> is the same as C<substr($var, $-[2], $+[2] - $-[2])>
1N/A
1N/A=item C<$3> is the same as C<substr $var, $-[3], $+[3] - $-[3])>
1N/A
1N/A=back
1N/A
1N/A=item HANDLE->format_name(EXPR)
1N/A
1N/A=item $FORMAT_NAME
1N/A
1N/A=item $~
1N/A
1N/AThe name of the current report format for the currently selected output
1N/Achannel. Default is the name of the filehandle. (Mnemonic: brother to
1N/AC<$^>.)
1N/A
1N/A=item HANDLE->format_top_name(EXPR)
1N/A
1N/A=item $FORMAT_TOP_NAME
1N/A
1N/A=item $^
1N/A
1N/AThe name of the current top-of-page format for the currently selected
1N/Aoutput channel. Default is the name of the filehandle with _TOP
1N/Aappended. (Mnemonic: points to top of page.)
1N/A
1N/A=item IO::Handle->format_line_break_characters EXPR
1N/A
1N/A=item $FORMAT_LINE_BREAK_CHARACTERS
1N/A
1N/A=item $:
1N/A
1N/AThe current set of characters after which a string may be broken to
1N/Afill continuation fields (starting with ^) in a format. Default is
1N/AS<" \n-">, to break on whitespace or hyphens. (Mnemonic: a "colon" in
1N/Apoetry is a part of a line.)
1N/A
1N/A=item IO::Handle->format_formfeed EXPR
1N/A
1N/A=item $FORMAT_FORMFEED
1N/A
1N/A=item $^L
1N/A
1N/AWhat formats output as a form feed. Default is \f.
1N/A
1N/A=item $ACCUMULATOR
1N/A
1N/A=item $^A
1N/A
1N/AThe current value of the write() accumulator for format() lines. A format
1N/Acontains formline() calls that put their result into C<$^A>. After
1N/Acalling its format, write() prints out the contents of C<$^A> and empties.
1N/ASo you never really see the contents of C<$^A> unless you call
1N/Aformline() yourself and then look at it. See L<perlform> and
1N/AL<perlfunc/formline()>.
1N/A
1N/A=item $CHILD_ERROR
1N/A
1N/A=item $?
1N/A
1N/AThe status returned by the last pipe close, backtick (C<``>) command,
1N/Asuccessful call to wait() or waitpid(), or from the system()
1N/Aoperator. This is just the 16-bit status word returned by the
1N/Await() system call (or else is made up to look like it). Thus, the
1N/Aexit value of the subprocess is really (C<<< $? >> 8 >>>), and
1N/AC<$? & 127> gives which signal, if any, the process died from, and
1N/AC<$? & 128> reports whether there was a core dump. (Mnemonic:
1N/Asimilar to B<sh> and B<ksh>.)
1N/A
1N/AAdditionally, if the C<h_errno> variable is supported in C, its value
1N/Ais returned via $? if any C<gethost*()> function fails.
1N/A
1N/AIf you have installed a signal handler for C<SIGCHLD>, the
1N/Avalue of C<$?> will usually be wrong outside that handler.
1N/A
1N/AInside an C<END> subroutine C<$?> contains the value that is going to be
1N/Agiven to C<exit()>. You can modify C<$?> in an C<END> subroutine to
1N/Achange the exit status of your program. For example:
1N/A
1N/A END {
1N/A $? = 1 if $? == 255; # die would make it 255
1N/A }
1N/A
1N/AUnder VMS, the pragma C<use vmsish 'status'> makes C<$?> reflect the
1N/Aactual VMS exit status, instead of the default emulation of POSIX
1N/Astatus; see L<perlvms/$?> for details.
1N/A
1N/AAlso see L<Error Indicators>.
1N/A
1N/A=item ${^ENCODING}
1N/A
1N/AThe I<object reference> to the Encode object that is used to convert
1N/Athe source code to Unicode. Thanks to this variable your perl script
1N/Adoes not have to be written in UTF-8. Default is I<undef>. The direct
1N/Amanipulation of this variable is highly discouraged. See L<encoding>
1N/Afor more details.
1N/A
1N/A=item $OS_ERROR
1N/A
1N/A=item $ERRNO
1N/A
1N/A=item $!
1N/A
1N/AIf used numerically, yields the current value of the C C<errno>
1N/Avariable, or in other words, if a system or library call fails, it
1N/Asets this variable. This means that the value of C<$!> is meaningful
1N/Aonly I<immediately> after a B<failure>:
1N/A
1N/A if (open(FH, $filename)) {
1N/A # Here $! is meaningless.
1N/A ...
1N/A } else {
1N/A # ONLY here is $! meaningful.
1N/A ...
1N/A # Already here $! might be meaningless.
1N/A }
1N/A # Since here we might have either success or failure,
1N/A # here $! is meaningless.
1N/A
1N/AIn the above I<meaningless> stands for anything: zero, non-zero,
1N/AC<undef>. A successful system or library call does B<not> set
1N/Athe variable to zero.
1N/A
1N/AIf used as a string, yields the corresponding system error string.
1N/AYou can assign a number to C<$!> to set I<errno> if, for instance,
1N/Ayou want C<"$!"> to return the string for error I<n>, or you want
1N/Ato set the exit value for the die() operator. (Mnemonic: What just
1N/Awent bang?)
1N/A
1N/AAlso see L<Error Indicators>.
1N/A
1N/A=item %!
1N/A
1N/AEach element of C<%!> has a true value only if C<$!> is set to that
1N/Avalue. For example, C<$!{ENOENT}> is true if and only if the current
1N/Avalue of C<$!> is C<ENOENT>; that is, if the most recent error was
1N/A"No such file or directory" (or its moral equivalent: not all operating
1N/Asystems give that exact error, and certainly not all languages).
1N/ATo check if a particular key is meaningful on your system, use
1N/AC<exists $!{the_key}>; for a list of legal keys, use C<keys %!>.
1N/ASee L<Errno> for more information, and also see above for the
1N/Avalidity of C<$!>.
1N/A
1N/A=item $EXTENDED_OS_ERROR
1N/A
1N/A=item $^E
1N/A
1N/AError information specific to the current operating system. At
1N/Athe moment, this differs from C<$!> under only VMS, OS/2, and Win32
1N/A(and for MacPerl). On all other platforms, C<$^E> is always just
1N/Athe same as C<$!>.
1N/A
1N/AUnder VMS, C<$^E> provides the VMS status value from the last
1N/Asystem error. This is more specific information about the last
1N/Asystem error than that provided by C<$!>. This is particularly
1N/Aimportant when C<$!> is set to B<EVMSERR>.
1N/A
1N/AUnder OS/2, C<$^E> is set to the error code of the last call to
1N/AOS/2 API either via CRT, or directly from perl.
1N/A
1N/AUnder Win32, C<$^E> always returns the last error information
1N/Areported by the Win32 call C<GetLastError()> which describes
1N/Athe last error from within the Win32 API. Most Win32-specific
1N/Acode will report errors via C<$^E>. ANSI C and Unix-like calls
1N/Aset C<errno> and so most portable Perl code will report errors
1N/Avia C<$!>.
1N/A
1N/ACaveats mentioned in the description of C<$!> generally apply to
1N/AC<$^E>, also. (Mnemonic: Extra error explanation.)
1N/A
1N/AAlso see L<Error Indicators>.
1N/A
1N/A=item $EVAL_ERROR
1N/A
1N/A=item $@
1N/A
1N/AThe Perl syntax error message from the last eval() operator.
1N/AIf $@ is the null string, the last eval() parsed and executed
1N/Acorrectly (although the operations you invoked may have failed in the
1N/Anormal fashion). (Mnemonic: Where was the syntax error "at"?)
1N/A
1N/AWarning messages are not collected in this variable. You can,
1N/Ahowever, set up a routine to process warnings by setting C<$SIG{__WARN__}>
1N/Aas described below.
1N/A
1N/AAlso see L<Error Indicators>.
1N/A
1N/A=item $PROCESS_ID
1N/A
1N/A=item $PID
1N/A
1N/A=item $$
1N/A
1N/AThe process number of the Perl running this script. You should
1N/Aconsider this variable read-only, although it will be altered
1N/Aacross fork() calls. (Mnemonic: same as shells.)
1N/A
1N/ANote for Linux users: on Linux, the C functions C<getpid()> and
1N/AC<getppid()> return different values from different threads. In order to
1N/Abe portable, this behavior is not reflected by C<$$>, whose value remains
1N/Aconsistent across threads. If you want to call the underlying C<getpid()>,
1N/Ayou may use the CPAN module C<Linux::Pid>.
1N/A
1N/A=item $REAL_USER_ID
1N/A
1N/A=item $UID
1N/A
1N/A=item $<
1N/A
1N/AThe real uid of this process. (Mnemonic: it's the uid you came I<from>,
1N/Aif you're running setuid.) You can change both the real uid and
1N/Athe effective uid at the same time by using POSIX::setuid().
1N/A
1N/A=item $EFFECTIVE_USER_ID
1N/A
1N/A=item $EUID
1N/A
1N/A=item $>
1N/A
1N/AThe effective uid of this process. Example:
1N/A
1N/A $< = $>; # set real to effective uid
1N/A ($<,$>) = ($>,$<); # swap real and effective uid
1N/A
1N/AYou can change both the effective uid and the real uid at the same
1N/Atime by using POSIX::setuid().
1N/A
1N/A(Mnemonic: it's the uid you went I<to>, if you're running setuid.)
1N/AC<< $< >> and C<< $> >> can be swapped only on machines
1N/Asupporting setreuid().
1N/A
1N/A=item $REAL_GROUP_ID
1N/A
1N/A=item $GID
1N/A
1N/A=item $(
1N/A
1N/AThe real gid of this process. If you are on a machine that supports
1N/Amembership in multiple groups simultaneously, gives a space separated
1N/Alist of groups you are in. The first number is the one returned by
1N/Agetgid(), and the subsequent ones by getgroups(), one of which may be
1N/Athe same as the first number.
1N/A
1N/AHowever, a value assigned to C<$(> must be a single number used to
1N/Aset the real gid. So the value given by C<$(> should I<not> be assigned
1N/Aback to C<$(> without being forced numeric, such as by adding zero.
1N/A
1N/AYou can change both the real gid and the effective gid at the same
1N/Atime by using POSIX::setgid().
1N/A
1N/A(Mnemonic: parentheses are used to I<group> things. The real gid is the
1N/Agroup you I<left>, if you're running setgid.)
1N/A
1N/A=item $EFFECTIVE_GROUP_ID
1N/A
1N/A=item $EGID
1N/A
1N/A=item $)
1N/A
1N/AThe effective gid of this process. If you are on a machine that
1N/Asupports membership in multiple groups simultaneously, gives a space
1N/Aseparated list of groups you are in. The first number is the one
1N/Areturned by getegid(), and the subsequent ones by getgroups(), one of
1N/Awhich may be the same as the first number.
1N/A
1N/ASimilarly, a value assigned to C<$)> must also be a space-separated
1N/Alist of numbers. The first number sets the effective gid, and
1N/Athe rest (if any) are passed to setgroups(). To get the effect of an
1N/Aempty list for setgroups(), just repeat the new effective gid; that is,
1N/Ato force an effective gid of 5 and an effectively empty setgroups()
1N/Alist, say C< $) = "5 5" >.
1N/A
1N/AYou can change both the effective gid and the real gid at the same
1N/Atime by using POSIX::setgid() (use only a single numeric argument).
1N/A
1N/A(Mnemonic: parentheses are used to I<group> things. The effective gid
1N/Ais the group that's I<right> for you, if you're running setgid.)
1N/A
1N/AC<< $< >>, C<< $> >>, C<$(> and C<$)> can be set only on
1N/Amachines that support the corresponding I<set[re][ug]id()> routine. C<$(>
1N/Aand C<$)> can be swapped only on machines supporting setregid().
1N/A
1N/A=item $PROGRAM_NAME
1N/A
1N/A=item $0
1N/A
1N/AContains the name of the program being executed.
1N/A
1N/AOn some (read: not all) operating systems assigning to C<$0> modifies
1N/Athe argument area that the C<ps> program sees. On some platforms you
1N/Amay have to use special C<ps> options or a different C<ps> to see the
1N/Achanges. Modifying the $0 is more useful as a way of indicating the
1N/Acurrent program state than it is for hiding the program you're
1N/Arunning. (Mnemonic: same as B<sh> and B<ksh>.)
1N/A
1N/ANote that there are platform specific limitations on the the maximum
1N/Alength of C<$0>. In the most extreme case it may be limited to the
1N/Aspace occupied by the original C<$0>.
1N/A
1N/AIn some platforms there may be arbitrary amount of padding, for
1N/Aexample space characters, after the modified name as shown by C<ps>.
1N/AIn some platforms this padding may extend all the way to the original
1N/Alength of the argument area, no matter what you do (this is the case
1N/Afor example with Linux 2.2).
1N/A
1N/ANote for BSD users: setting C<$0> does not completely remove "perl"
1N/Afrom the ps(1) output. For example, setting C<$0> to C<"foobar"> may
1N/Aresult in C<"perl: foobar (perl)"> (whether both the C<"perl: "> prefix
1N/Aand the " (perl)" suffix are shown depends on your exact BSD variant
1N/Aand version). This is an operating system feature, Perl cannot help it.
1N/A
1N/AIn multithreaded scripts Perl coordinates the threads so that any
1N/Athread may modify its copy of the C<$0> and the change becomes visible
1N/Ato ps(1) (assuming the operating system plays along). Note that the
1N/Athe view of C<$0> the other threads have will not change since they
1N/Ahave their own copies of it.
1N/A
1N/A=item $[
1N/A
1N/AThe index of the first element in an array, and of the first character
1N/Ain a substring. Default is 0, but you could theoretically set it
1N/Ato 1 to make Perl behave more like B<awk> (or Fortran) when
1N/Asubscripting and when evaluating the index() and substr() functions.
1N/A(Mnemonic: [ begins subscripts.)
1N/A
1N/AAs of release 5 of Perl, assignment to C<$[> is treated as a compiler
1N/Adirective, and cannot influence the behavior of any other file.
1N/A(That's why you can only assign compile-time constants to it.)
1N/AIts use is highly discouraged.
1N/A
1N/ANote that, unlike other compile-time directives (such as L<strict>),
1N/Aassignment to $[ can be seen from outer lexical scopes in the same file.
1N/AHowever, you can use local() on it to strictly bound its value to a
1N/Alexical block.
1N/A
1N/A=item $]
1N/A
1N/AThe version + patchlevel / 1000 of the Perl interpreter. This variable
1N/Acan be used to determine whether the Perl interpreter executing a
1N/Ascript is in the right range of versions. (Mnemonic: Is this version
1N/Aof perl in the right bracket?) Example:
1N/A
1N/A warn "No checksumming!\n" if $] < 3.019;
1N/A
1N/ASee also the documentation of C<use VERSION> and C<require VERSION>
1N/Afor a convenient way to fail if the running Perl interpreter is too old.
1N/A
1N/AWhen testing the variable, to steer clear of floating point
1N/Ainaccuracies you might want to prefer the inequality tests C<< < >>
1N/Aand C<< > >> to the tests containing equivalence: C<< <= >>, C<< == >>,
1N/Aand C<< >= >>.
1N/A
1N/AThe floating point representation can sometimes lead to inaccurate
1N/Anumeric comparisons. See C<$^V> for a more modern representation of
1N/Athe Perl version that allows accurate string comparisons.
1N/A
1N/A=item $COMPILING
1N/A
1N/A=item $^C
1N/A
1N/AThe current value of the flag associated with the B<-c> switch.
1N/AMainly of use with B<-MO=...> to allow code to alter its behavior
1N/Awhen being compiled, such as for example to AUTOLOAD at compile
1N/Atime rather than normal, deferred loading. See L<perlcc>. Setting
1N/AC<$^C = 1> is similar to calling C<B::minus_c>.
1N/A
1N/A=item $DEBUGGING
1N/A
1N/A=item $^D
1N/A
1N/AThe current value of the debugging flags. (Mnemonic: value of B<-D>
1N/Aswitch.) May be read or set. Like its command-line equivalent, you can use
1N/Anumeric or symbolic values, eg C<$^D = 10> or C<$^D = "st">.
1N/A
1N/A=item $SYSTEM_FD_MAX
1N/A
1N/A=item $^F
1N/A
1N/AThe maximum system file descriptor, ordinarily 2. System file
1N/Adescriptors are passed to exec()ed processes, while higher file
1N/Adescriptors are not. Also, during an open(), system file descriptors are
1N/Apreserved even if the open() fails. (Ordinary file descriptors are
1N/Aclosed before the open() is attempted.) The close-on-exec
1N/Astatus of a file descriptor will be decided according to the value of
1N/AC<$^F> when the corresponding file, pipe, or socket was opened, not the
1N/Atime of the exec().
1N/A
1N/A=item $^H
1N/A
1N/AWARNING: This variable is strictly for internal use only. Its availability,
1N/Abehavior, and contents are subject to change without notice.
1N/A
1N/AThis variable contains compile-time hints for the Perl interpreter. At the
1N/Aend of compilation of a BLOCK the value of this variable is restored to the
1N/Avalue when the interpreter started to compile the BLOCK.
1N/A
1N/AWhen perl begins to parse any block construct that provides a lexical scope
1N/A(e.g., eval body, required file, subroutine body, loop body, or conditional
1N/Ablock), the existing value of $^H is saved, but its value is left unchanged.
1N/AWhen the compilation of the block is completed, it regains the saved value.
1N/ABetween the points where its value is saved and restored, code that
1N/Aexecutes within BEGIN blocks is free to change the value of $^H.
1N/A
1N/AThis behavior provides the semantic of lexical scoping, and is used in,
1N/Afor instance, the C<use strict> pragma.
1N/A
1N/AThe contents should be an integer; different bits of it are used for
1N/Adifferent pragmatic flags. Here's an example:
1N/A
1N/A sub add_100 { $^H |= 0x100 }
1N/A
1N/A sub foo {
1N/A BEGIN { add_100() }
1N/A bar->baz($boon);
1N/A }
1N/A
1N/AConsider what happens during execution of the BEGIN block. At this point
1N/Athe BEGIN block has already been compiled, but the body of foo() is still
1N/Abeing compiled. The new value of $^H will therefore be visible only while
1N/Athe body of foo() is being compiled.
1N/A
1N/ASubstitution of the above BEGIN block with:
1N/A
1N/A BEGIN { require strict; strict->import('vars') }
1N/A
1N/Ademonstrates how C<use strict 'vars'> is implemented. Here's a conditional
1N/Aversion of the same lexical pragma:
1N/A
1N/A BEGIN { require strict; strict->import('vars') if $condition }
1N/A
1N/A=item %^H
1N/A
1N/AWARNING: This variable is strictly for internal use only. Its availability,
1N/Abehavior, and contents are subject to change without notice.
1N/A
1N/AThe %^H hash provides the same scoping semantic as $^H. This makes it
1N/Auseful for implementation of lexically scoped pragmas.
1N/A
1N/A=item $INPLACE_EDIT
1N/A
1N/A=item $^I
1N/A
1N/AThe current value of the inplace-edit extension. Use C<undef> to disable
1N/Ainplace editing. (Mnemonic: value of B<-i> switch.)
1N/A
1N/A=item $^M
1N/A
1N/ABy default, running out of memory is an untrappable, fatal error.
1N/AHowever, if suitably built, Perl can use the contents of C<$^M>
1N/Aas an emergency memory pool after die()ing. Suppose that your Perl
1N/Awere compiled with -DPERL_EMERGENCY_SBRK and used Perl's malloc.
1N/AThen
1N/A
1N/A $^M = 'a' x (1 << 16);
1N/A
1N/Awould allocate a 64K buffer for use in an emergency. See the
1N/AF<INSTALL> file in the Perl distribution for information on how to
1N/Aenable this option. To discourage casual use of this advanced
1N/Afeature, there is no L<English|English> long name for this variable.
1N/A
1N/A=item $OSNAME
1N/A
1N/A=item $^O
1N/A
1N/AThe name of the operating system under which this copy of Perl was
1N/Abuilt, as determined during the configuration process. The value
1N/Ais identical to C<$Config{'osname'}>. See also L<Config> and the
1N/AB<-V> command-line switch documented in L<perlrun>.
1N/A
1N/AIn Windows platforms, $^O is not very helpful: since it is always
1N/AC<MSWin32>, it doesn't tell the difference between
1N/A95/98/ME/NT/2000/XP/CE/.NET. Use Win32::GetOSName() or
1N/AWin32::GetOSVersion() (see L<Win32> and L<perlport>) to distinguish
1N/Abetween the variants.
1N/A
1N/A=item ${^OPEN}
1N/A
1N/AAn internal variable used by PerlIO. A string in two parts, separated
1N/Aby a C<\0> byte, the first part describes the input layers, the second
1N/Apart describes the output layers.
1N/A
1N/A=item $PERLDB
1N/A
1N/A=item $^P
1N/A
1N/AThe internal variable for debugging support. The meanings of the
1N/Avarious bits are subject to change, but currently indicate:
1N/A
1N/A=over 6
1N/A
1N/A=item 0x01
1N/A
1N/ADebug subroutine enter/exit.
1N/A
1N/A=item 0x02
1N/A
1N/ALine-by-line debugging.
1N/A
1N/A=item 0x04
1N/A
1N/ASwitch off optimizations.
1N/A
1N/A=item 0x08
1N/A
1N/APreserve more data for future interactive inspections.
1N/A
1N/A=item 0x10
1N/A
1N/AKeep info about source lines on which a subroutine is defined.
1N/A
1N/A=item 0x20
1N/A
1N/AStart with single-step on.
1N/A
1N/A=item 0x40
1N/A
1N/AUse subroutine address instead of name when reporting.
1N/A
1N/A=item 0x80
1N/A
1N/AReport C<goto &subroutine> as well.
1N/A
1N/A=item 0x100
1N/A
1N/AProvide informative "file" names for evals based on the place they were compiled.
1N/A
1N/A=item 0x200
1N/A
1N/AProvide informative names to anonymous subroutines based on the place they
1N/Awere compiled.
1N/A
1N/A=item 0x400
1N/A
1N/ADebug assertion subroutines enter/exit.
1N/A
1N/A=back
1N/A
1N/ASome bits may be relevant at compile-time only, some at
1N/Arun-time only. This is a new mechanism and the details may change.
1N/A
1N/A=item $LAST_REGEXP_CODE_RESULT
1N/A
1N/A=item $^R
1N/A
1N/AThe result of evaluation of the last successful C<(?{ code })>
1N/Aregular expression assertion (see L<perlre>). May be written to.
1N/A
1N/A=item $EXCEPTIONS_BEING_CAUGHT
1N/A
1N/A=item $^S
1N/A
1N/ACurrent state of the interpreter.
1N/A
1N/A $^S State
1N/A --------- -------------------
1N/A undef Parsing module/eval
1N/A true (1) Executing an eval
1N/A false (0) Otherwise
1N/A
1N/AThe first state may happen in $SIG{__DIE__} and $SIG{__WARN__} handlers.
1N/A
1N/A=item $BASETIME
1N/A
1N/A=item $^T
1N/A
1N/AThe time at which the program began running, in seconds since the
1N/Aepoch (beginning of 1970). The values returned by the B<-M>, B<-A>,
1N/Aand B<-C> filetests are based on this value.
1N/A
1N/A=item ${^TAINT}
1N/A
1N/AReflects if taint mode is on or off. 1 for on (the program was run with
1N/AB<-T>), 0 for off, -1 when only taint warnings are enabled (i.e. with
1N/AB<-t> or B<-TU>).
1N/A
1N/A=item ${^UNICODE}
1N/A
1N/AReflects certain Unicode settings of Perl. See L<perlrun>
1N/Adocumentation for the C<-C> switch for more information about
1N/Athe possible values. This variable is set during Perl startup
1N/Aand is thereafter read-only.
1N/A
1N/A=item $PERL_VERSION
1N/A
1N/A=item $^V
1N/A
1N/AThe revision, version, and subversion of the Perl interpreter, represented
1N/Aas a string composed of characters with those ordinals. Thus in Perl v5.6.0
1N/Ait equals C<chr(5) . chr(6) . chr(0)> and will return true for
1N/AC<$^V eq v5.6.0>. Note that the characters in this string value can
1N/Apotentially be in Unicode range.
1N/A
1N/AThis can be used to determine whether the Perl interpreter executing a
1N/Ascript is in the right range of versions. (Mnemonic: use ^V for Version
1N/AControl.) Example:
1N/A
1N/A warn "No \"our\" declarations!\n" if $^V and $^V lt v5.6.0;
1N/A
1N/ATo convert C<$^V> into its string representation use sprintf()'s
1N/AC<"%vd"> conversion:
1N/A
1N/A printf "version is v%vd\n", $^V; # Perl's version
1N/A
1N/ASee the documentation of C<use VERSION> and C<require VERSION>
1N/Afor a convenient way to fail if the running Perl interpreter is too old.
1N/A
1N/ASee also C<$]> for an older representation of the Perl version.
1N/A
1N/A=item $WARNING
1N/A
1N/A=item $^W
1N/A
1N/AThe current value of the warning switch, initially true if B<-w>
1N/Awas used, false otherwise, but directly modifiable. (Mnemonic:
1N/Arelated to the B<-w> switch.) See also L<warnings>.
1N/A
1N/A=item ${^WARNING_BITS}
1N/A
1N/AThe current set of warning checks enabled by the C<use warnings> pragma.
1N/ASee the documentation of C<warnings> for more details.
1N/A
1N/A=item $EXECUTABLE_NAME
1N/A
1N/A=item $^X
1N/A
1N/AThe name used to execute the current copy of Perl, from C's
1N/AC<argv[0]>.
1N/A
1N/ADepending on the host operating system, the value of $^X may be
1N/Aa relative or absolute pathname of the perl program file, or may
1N/Abe the string used to invoke perl but not the pathname of the
1N/Aperl program file. Also, most operating systems permit invoking
1N/Aprograms that are not in the PATH environment variable, so there
1N/Ais no guarantee that the value of $^X is in PATH. For VMS, the
1N/Avalue may or may not include a version number.
1N/A
1N/AYou usually can use the value of $^X to re-invoke an independent
1N/Acopy of the same perl that is currently running, e.g.,
1N/A
1N/A @first_run = `$^X -le "print int rand 100 for 1..100"`;
1N/A
1N/ABut recall that not all operating systems support forking or
1N/Acapturing of the output of commands, so this complex statement
1N/Amay not be portable.
1N/A
1N/AIt is not safe to use the value of $^X as a path name of a file,
1N/Aas some operating systems that have a mandatory suffix on
1N/Aexecutable files do not require use of the suffix when invoking
1N/Aa command. To convert the value of $^X to a path name, use the
1N/Afollowing statements:
1N/A
1N/A# Build up a set of file names (not command names).
1N/A use Config;
1N/A $this_perl = $^X;
1N/A if ($^O ne 'VMS')
1N/A {$this_perl .= $Config{_exe}
1N/A unless $this_perl =~ m/$Config{_exe}$/i;}
1N/A
1N/ABecause many operating systems permit anyone with read access to
1N/Athe Perl program file to make a copy of it, patch the copy, and
1N/Athen execute the copy, the security-conscious Perl programmer
1N/Ashould take care to invoke the installed copy of perl, not the
1N/Acopy referenced by $^X. The following statements accomplish
1N/Athis goal, and produce a pathname that can be invoked as a
1N/Acommand or referenced as a file.
1N/A
1N/A use Config;
1N/A $secure_perl_path = $Config{perlpath};
1N/A if ($^O ne 'VMS')
1N/A {$secure_perl_path .= $Config{_exe}
1N/A unless $secure_perl_path =~ m/$Config{_exe}$/i;}
1N/A
1N/A=item ARGV
1N/A
1N/AThe special filehandle that iterates over command-line filenames in
1N/AC<@ARGV>. Usually written as the null filehandle in the angle operator
1N/AC<< <> >>. Note that currently C<ARGV> only has its magical effect
1N/Awithin the C<< <> >> operator; elsewhere it is just a plain filehandle
1N/Acorresponding to the last file opened by C<< <> >>. In particular,
1N/Apassing C<\*ARGV> as a parameter to a function that expects a filehandle
1N/Amay not cause your function to automatically read the contents of all the
1N/Afiles in C<@ARGV>.
1N/A
1N/A=item $ARGV
1N/A
1N/Acontains the name of the current file when reading from <>.
1N/A
1N/A=item @ARGV
1N/A
1N/AThe array @ARGV contains the command-line arguments intended for
1N/Athe script. C<$#ARGV> is generally the number of arguments minus
1N/Aone, because C<$ARGV[0]> is the first argument, I<not> the program's
1N/Acommand name itself. See C<$0> for the command name.
1N/A
1N/A=item ARGVOUT
1N/A
1N/AThe special filehandle that points to the currently open output file
1N/Awhen doing edit-in-place processing with B<-i>. Useful when you have
1N/Ato do a lot of inserting and don't want to keep modifying $_. See
1N/AL<perlrun> for the B<-i> switch.
1N/A
1N/A=item @F
1N/A
1N/AThe array @F contains the fields of each line read in when autosplit
1N/Amode is turned on. See L<perlrun> for the B<-a> switch. This array
1N/Ais package-specific, and must be declared or given a full package name
1N/Aif not in package main when running under C<strict 'vars'>.
1N/A
1N/A=item @INC
1N/A
1N/AThe array @INC contains the list of places that the C<do EXPR>,
1N/AC<require>, or C<use> constructs look for their library files. It
1N/Ainitially consists of the arguments to any B<-I> command-line
1N/Aswitches, followed by the default Perl library, probably
1N/AF</usr/local/lib/perl>, followed by ".", to represent the current
1N/Adirectory. ("." will not be appended if taint checks are enabled, either by
1N/AC<-T> or by C<-t>.) If you need to modify this at runtime, you should use
1N/Athe C<use lib> pragma to get the machine-dependent library properly
1N/Aloaded also:
1N/A
1N/A use lib '/mypath/libdir/';
1N/A use SomeMod;
1N/A
1N/AYou can also insert hooks into the file inclusion system by putting Perl
1N/Acode directly into @INC. Those hooks may be subroutine references, array
1N/Areferences or blessed objects. See L<perlfunc/require> for details.
1N/A
1N/A=item @_
1N/A
1N/AWithin a subroutine the array @_ contains the parameters passed to that
1N/Asubroutine. See L<perlsub>.
1N/A
1N/A=item %INC
1N/A
1N/AThe hash %INC contains entries for each filename included via the
1N/AC<do>, C<require>, or C<use> operators. The key is the filename
1N/Ayou specified (with module names converted to pathnames), and the
1N/Avalue is the location of the file found. The C<require>
1N/Aoperator uses this hash to determine whether a particular file has
1N/Aalready been included.
1N/A
1N/AIf the file was loaded via a hook (e.g. a subroutine reference, see
1N/AL<perlfunc/require> for a description of these hooks), this hook is
1N/Aby default inserted into %INC in place of a filename. Note, however,
1N/Athat the hook may have set the %INC entry by itself to provide some more
1N/Aspecific info.
1N/A
1N/A=item %ENV
1N/A
1N/A=item $ENV{expr}
1N/A
1N/AThe hash %ENV contains your current environment. Setting a
1N/Avalue in C<ENV> changes the environment for any child processes
1N/Ayou subsequently fork() off.
1N/A
1N/A=item %SIG
1N/A
1N/A=item $SIG{expr}
1N/A
1N/AThe hash %SIG contains signal handlers for signals. For example:
1N/A
1N/A sub handler { # 1st argument is signal name
1N/A my($sig) = @_;
1N/A print "Caught a SIG$sig--shutting down\n";
1N/A close(LOG);
1N/A exit(0);
1N/A }
1N/A
1N/A $SIG{'INT'} = \&handler;
1N/A $SIG{'QUIT'} = \&handler;
1N/A ...
1N/A $SIG{'INT'} = 'DEFAULT'; # restore default action
1N/A $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT
1N/A
1N/AUsing a value of C<'IGNORE'> usually has the effect of ignoring the
1N/Asignal, except for the C<CHLD> signal. See L<perlipc> for more about
1N/Athis special case.
1N/A
1N/AHere are some other examples:
1N/A
1N/A $SIG{"PIPE"} = "Plumber"; # assumes main::Plumber (not recommended)
1N/A $SIG{"PIPE"} = \&Plumber; # just fine; assume current Plumber
1N/A $SIG{"PIPE"} = *Plumber; # somewhat esoteric
1N/A $SIG{"PIPE"} = Plumber(); # oops, what did Plumber() return??
1N/A
1N/ABe sure not to use a bareword as the name of a signal handler,
1N/Alest you inadvertently call it.
1N/A
1N/AIf your system has the sigaction() function then signal handlers are
1N/Ainstalled using it. This means you get reliable signal handling.
1N/A
1N/AThe default delivery policy of signals changed in Perl 5.8.0 from
1N/Aimmediate (also known as "unsafe") to deferred, also known as
1N/A"safe signals". See L<perlipc> for more information.
1N/A
1N/ACertain internal hooks can be also set using the %SIG hash. The
1N/Aroutine indicated by C<$SIG{__WARN__}> is called when a warning message is
1N/Aabout to be printed. The warning message is passed as the first
1N/Aargument. The presence of a __WARN__ hook causes the ordinary printing
1N/Aof warnings to STDERR to be suppressed. You can use this to save warnings
1N/Ain a variable, or turn warnings into fatal errors, like this:
1N/A
1N/A local $SIG{__WARN__} = sub { die $_[0] };
1N/A eval $proggie;
1N/A
1N/AThe routine indicated by C<$SIG{__DIE__}> is called when a fatal exception
1N/Ais about to be thrown. The error message is passed as the first
1N/Aargument. When a __DIE__ hook routine returns, the exception
1N/Aprocessing continues as it would have in the absence of the hook,
1N/Aunless the hook routine itself exits via a C<goto>, a loop exit, or a die().
1N/AThe C<__DIE__> handler is explicitly disabled during the call, so that you
1N/Acan die from a C<__DIE__> handler. Similarly for C<__WARN__>.
1N/A
1N/ADue to an implementation glitch, the C<$SIG{__DIE__}> hook is called
1N/Aeven inside an eval(). Do not use this to rewrite a pending exception
1N/Ain C<$@>, or as a bizarre substitute for overriding CORE::GLOBAL::die().
1N/AThis strange action at a distance may be fixed in a future release
1N/Aso that C<$SIG{__DIE__}> is only called if your program is about
1N/Ato exit, as was the original intent. Any other use is deprecated.
1N/A
1N/AC<__DIE__>/C<__WARN__> handlers are very special in one respect:
1N/Athey may be called to report (probable) errors found by the parser.
1N/AIn such a case the parser may be in inconsistent state, so any
1N/Aattempt to evaluate Perl code from such a handler will probably
1N/Aresult in a segfault. This means that warnings or errors that
1N/Aresult from parsing Perl should be used with extreme caution, like
1N/Athis:
1N/A
1N/A require Carp if defined $^S;
1N/A Carp::confess("Something wrong") if defined &Carp::confess;
1N/A die "Something wrong, but could not load Carp to give backtrace...
1N/A To see backtrace try starting Perl with -MCarp switch";
1N/A
1N/AHere the first line will load Carp I<unless> it is the parser who
1N/Acalled the handler. The second line will print backtrace and die if
1N/ACarp was available. The third line will be executed only if Carp was
1N/Anot available.
1N/A
1N/ASee L<perlfunc/die>, L<perlfunc/warn>, L<perlfunc/eval>, and
1N/AL<warnings> for additional information.
1N/A
1N/A=back
1N/A
1N/A=head2 Error Indicators
1N/A
1N/AThe variables C<$@>, C<$!>, C<$^E>, and C<$?> contain information
1N/Aabout different types of error conditions that may appear during
1N/Aexecution of a Perl program. The variables are shown ordered by
1N/Athe "distance" between the subsystem which reported the error and
1N/Athe Perl process. They correspond to errors detected by the Perl
1N/Ainterpreter, C library, operating system, or an external program,
1N/Arespectively.
1N/A
1N/ATo illustrate the differences between these variables, consider the
1N/Afollowing Perl expression, which uses a single-quoted string:
1N/A
1N/A eval q{
1N/A open my $pipe, "/cdrom/install |" or die $!;
1N/A my @res = <$pipe>;
1N/A close $pipe or die "bad pipe: $?, $!";
1N/A };
1N/A
1N/AAfter execution of this statement all 4 variables may have been set.
1N/A
1N/AC<$@> is set if the string to be C<eval>-ed did not compile (this
1N/Amay happen if C<open> or C<close> were imported with bad prototypes),
1N/Aor if Perl code executed during evaluation die()d . In these cases
1N/Athe value of $@ is the compile error, or the argument to C<die>
1N/A(which will interpolate C<$!> and C<$?>!). (See also L<Fatal>,
1N/Athough.)
1N/A
1N/AWhen the eval() expression above is executed, open(), C<< <PIPE> >>,
1N/Aand C<close> are translated to calls in the C run-time library and
1N/Athence to the operating system kernel. C<$!> is set to the C library's
1N/AC<errno> if one of these calls fails.
1N/A
1N/AUnder a few operating systems, C<$^E> may contain a more verbose
1N/Aerror indicator, such as in this case, "CDROM tray not closed."
1N/ASystems that do not support extended error messages leave C<$^E>
1N/Athe same as C<$!>.
1N/A
1N/AFinally, C<$?> may be set to non-0 value if the external program
1N/AF</cdrom/install> fails. The upper eight bits reflect specific
1N/Aerror conditions encountered by the program (the program's exit()
1N/Avalue). The lower eight bits reflect mode of failure, like signal
1N/Adeath and core dump information See wait(2) for details. In
1N/Acontrast to C<$!> and C<$^E>, which are set only if error condition
1N/Ais detected, the variable C<$?> is set on each C<wait> or pipe
1N/AC<close>, overwriting the old value. This is more like C<$@>, which
1N/Aon every eval() is always set on failure and cleared on success.
1N/A
1N/AFor more details, see the individual descriptions at C<$@>, C<$!>, C<$^E>,
1N/Aand C<$?>.
1N/A
1N/A=head2 Technical Note on the Syntax of Variable Names
1N/A
1N/AVariable names in Perl can have several formats. Usually, they
1N/Amust begin with a letter or underscore, in which case they can be
1N/Aarbitrarily long (up to an internal limit of 251 characters) and
1N/Amay contain letters, digits, underscores, or the special sequence
1N/AC<::> or C<'>. In this case, the part before the last C<::> or
1N/AC<'> is taken to be a I<package qualifier>; see L<perlmod>.
1N/A
1N/APerl variable names may also be a sequence of digits or a single
1N/Apunctuation or control character. These names are all reserved for
1N/Aspecial uses by Perl; for example, the all-digits names are used
1N/Ato hold data captured by backreferences after a regular expression
1N/Amatch. Perl has a special syntax for the single-control-character
1N/Anames: It understands C<^X> (caret C<X>) to mean the control-C<X>
1N/Acharacter. For example, the notation C<$^W> (dollar-sign caret
1N/AC<W>) is the scalar variable whose name is the single character
1N/Acontrol-C<W>. This is better than typing a literal control-C<W>
1N/Ainto your program.
1N/A
1N/AFinally, new in Perl 5.6, Perl variable names may be alphanumeric
1N/Astrings that begin with control characters (or better yet, a caret).
1N/AThese variables must be written in the form C<${^Foo}>; the braces
1N/Aare not optional. C<${^Foo}> denotes the scalar variable whose
1N/Aname is a control-C<F> followed by two C<o>'s. These variables are
1N/Areserved for future special uses by Perl, except for the ones that
1N/Abegin with C<^_> (control-underscore or caret-underscore). No
1N/Acontrol-character name that begins with C<^_> will acquire a special
1N/Ameaning in any future version of Perl; such names may therefore be
1N/Aused safely in programs. C<$^_> itself, however, I<is> reserved.
1N/A
1N/APerl identifiers that begin with digits, control characters, or
1N/Apunctuation characters are exempt from the effects of the C<package>
1N/Adeclaration and are always forced to be in package C<main>; they are
1N/Aalso exempt from C<strict 'vars'> errors. A few other names are also
1N/Aexempt in these ways:
1N/A
1N/A ENV STDIN
1N/A INC STDOUT
1N/A ARGV STDERR
1N/A ARGVOUT _
1N/A SIG
1N/A
1N/AIn particular, the new special C<${^_XYZ}> variables are always taken
1N/Ato be in package C<main>, regardless of any C<package> declarations
1N/Apresently in scope.
1N/A
1N/A=head1 BUGS
1N/A
1N/ADue to an unfortunate accident of Perl's implementation, C<use
1N/AEnglish> imposes a considerable performance penalty on all regular
1N/Aexpression matches in a program, regardless of whether they occur
1N/Ain the scope of C<use English>. For that reason, saying C<use
1N/AEnglish> in libraries is strongly discouraged. See the
1N/ADevel::SawAmpersand module documentation from CPAN
1N/A( http://www.cpan.org/modules/by-module/Devel/ )
1N/Afor more information.
1N/A
1N/AHaving to even think about the C<$^S> variable in your exception
1N/Ahandlers is simply wrong. C<$SIG{__DIE__}> as currently implemented
1N/Ainvites grievous and difficult to track down errors. Avoid it
1N/Aand use an C<END{}> or CORE::GLOBAL::die override instead.