X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/1fa81471adb3ec0d9247f45f13cf70a6919962c0..b76dad153351f50f46ba283bb0da075b93e89838:/pod/perlvar.pod
diff --git a/pod/perlvar.pod b/pod/perlvar.pod
index e504e23..35351b7 100644
--- a/pod/perlvar.pod
+++ b/pod/perlvar.pod
@@ -6,46 +6,46 @@ perlvar - Perl predefined variables
=head2 The Syntax of Variable Names
-Variable names in Perl can have several formats. Usually, they
+Variable names in Perl can have several formats. Usually, they
must begin with a letter or underscore, in which case they can be
arbitrarily long (up to an internal limit of 251 characters) and
may contain letters, digits, underscores, or the special sequence
-C<::> or C<'>. In this case, the part before the last C<::> or
+C<::> or C<'>. In this case, the part before the last C<::> or
C<'> is taken to be a I; see L.
-
-Perl variable names may also be a sequence of digits or a single
-punctuation or control character. These names are all reserved for
+A Unicode letter that is not ASCII is not considered to be a letter
+unless S> is in effect, and somewhat more complicated
+rules apply; see L for details.
+
+Perl variable names may also be a sequence of digits, a single
+punctuation character, or the two-character sequence: C<^> (caret or
+CIRCUMFLEX ACCENT) followed by any one of the characters C<[][A-Z^_?\]>.
+These names are all reserved for
special uses by Perl; for example, the all-digits names are used
to hold data captured by backreferences after a regular expression
-match. Perl has a special syntax for the single-control-character
-names: It understands C<^X> (caret C) to mean the control-C
-character. For example, the notation C<$^W> (dollar-sign caret
-C) is the scalar variable whose name is the single character
-control-C. This is better than typing a literal control-C
-into your program.
-
-Since Perl 5.6, Perl variable names may be alphanumeric
-strings that begin with control characters (or better yet, a caret).
-These variables must be written in the form C<${^Foo}>; the braces
-are not optional. C<${^Foo}> denotes the scalar variable whose
-name is a control-C followed by two C's. These variables are
+match.
+
+Since Perl v5.6.0, Perl variable names may also be alphanumeric strings
+preceded by a caret. These must all be written in the form C<${^Foo}>;
+the braces are not optional. C<${^Foo}> denotes the scalar variable
+whose name is considered to be a control-C followed by two C's.
+These variables are
reserved for future special uses by Perl, except for the ones that
-begin with C<^_> (control-underscore or caret-underscore). No
-control-character name that begins with C<^_> will acquire a special
+begin with C<^_> (caret-underscore). No
+name that begins with C<^_> will acquire a special
meaning in any future version of Perl; such names may therefore be
-used safely in programs. C<$^_> itself, however, I reserved.
+used safely in programs. C<$^_> itself, however, I reserved.
-Perl identifiers that begin with digits, control characters, or
+Perl identifiers that begin with digits or
punctuation characters are exempt from the effects of the C
declaration and are always forced to be in package C; they are
-also exempt from C errors. A few other names are also
+also exempt from C errors. A few other names are also
exempt in these ways:
- ENV STDIN
- INC STDOUT
- ARGV STDERR
- ARGVOUT
- SIG
+ ENV STDIN
+ INC STDOUT
+ ARGV STDERR
+ ARGVOUT
+ SIG
In particular, the special C<${^_XYZ}> variables are always taken
to be in package C, regardless of any C declarations
@@ -53,21 +53,17 @@ presently in scope.
=head1 SPECIAL VARIABLES
-The following names have special meaning to Perl. Most punctuation
+The following names have special meaning to Perl. Most punctuation
names have reasonable mnemonics, or analogs in the shells.
Nevertheless, if you wish to use long variable names, you need only say:
- use English;
+ use English;
-at the top of your program. This aliases all the short names to the long
-names in the current package. Some even have medium names, generally
-borrowed from B. To avoid a performance hit, if you don't need the
-C<$PREMATCH>, C<$MATCH>, or C<$POSTMATCH> it's best to use the C
-module without them:
+at the top of your program. This aliases all the short names to the long
+names in the current package. Some even have medium names, generally
+borrowed from B. For more info, please see L.
- use English '-no_match_vars';
-
-Before you continue, note the sort order for variables. In general, we
+Before you continue, note the sort order for variables. In general, we
first list the variables in case-insensitive, almost-lexigraphical
order (ignoring the C<{> or C<^> preceding words, as in C<${^UNICODE}>
or C<$^T>), although C<$_> and C<@_> move up to the top of the pile.
@@ -83,20 +79,20 @@ array, hash, and bareword.
=item $_
X<$_> X<$ARG>
-The default input and pattern-searching space. The following pairs are
+The default input and pattern-searching space. The following pairs are
equivalent:
- while (<>) {...} # equivalent only in while!
- while (defined($_ = <>)) {...}
+ while (<>) {...} # equivalent only in while!
+ while (defined($_ = <>)) {...}
- /^Subject:/
- $_ =~ /^Subject:/
+ /^Subject:/
+ $_ =~ /^Subject:/
- tr/a-z/A-Z/
- $_ =~ tr/a-z/A-Z/
+ tr/a-z/A-Z/
+ $_ =~ tr/a-z/A-Z/
- chomp
- chomp($_)
+ chomp
+ chomp($_)
Here are the places where Perl will assume C<$_> even if you don't use it:
@@ -106,10 +102,12 @@ Here are the places where Perl will assume C<$_> even if you don't use it:
The following functions use C<$_> as a default argument:
-abs, alarm, chomp, chop, chr, chroot, cos, defined, eval, exp, glob,
-hex, int, lc, lcfirst, length, log, lstat, mkdir, oct, ord, pos, print,
+abs, alarm, chomp, chop, chr, chroot,
+cos, defined, eval, evalbytes, exp, fc, glob, hex, int, lc,
+lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, printf,
quotemeta, readlink, readpipe, ref, require, reverse (in scalar context only),
-rmdir, sin, split (on its second argument), sqrt, stat, study, uc, ucfirst,
+rmdir, say, sin, split (for its second
+argument), sqrt, stat, study, uc, ucfirst,
unlink, unpack.
=item *
@@ -137,16 +135,26 @@ The implicit variable of C.
=item *
-The default place to put an input record when a C<< >>
+The default place to put the next value or input record
+when a C<< >>, C, C or C
operation's result is tested by itself as the sole criterion of a C
-test. Outside a C test, this will not happen.
+test. Outside a C test, this will not happen.
=back
-As C<$_> is a global variable, this may lead in some cases to unwanted
-side-effects. As of perl 5.9.1, you can now use a lexical version of
-C<$_> by declaring it in a file or in a block with C. Moreover,
-declaring C restores the global C<$_> in the current scope.
+C<$_> is by default a global variable. However, as
+of perl v5.10.0, you can use a lexical version of
+C<$_> by declaring it in a file or in a block with C. Moreover,
+declaring C restores the global C<$_> in the current scope. Though
+this seemed like a good idea at the time it was introduced, lexical C<$_>
+actually causes more problems than it solves. If you call a function that
+expects to be passed information via C<$_>, it may or may not work,
+depending on how the function is written, there not being any easy way to
+solve this. Just avoid lexical C<$_>, unless you are feeling particularly
+masochistic. For this reason lexical C<$_> is still experimental and will
+produce a warning unless warnings have been disabled. As with other
+experimental features, the behavior of lexical C<$_> is subject to change
+without notice, including change into a fatal error.
Mnemonic: underline is understood in certain operations.
@@ -156,8 +164,8 @@ Mnemonic: underline is understood in certain operations.
X<@_> X<@ARG>
Within a subroutine the array C<@_> contains the parameters passed to
-that subroutine. Inside a subroutine, C<@_> is the default array for
-the array operators C, C, C, and C.
+that subroutine. Inside a subroutine, C<@_> is the default array for
+the array operators C and C.
See L.
@@ -168,13 +176,13 @@ X<$"> X<$LIST_SEPARATOR>
When an array or an array slice is interpolated into a double-quoted
string or a similar context such as C, its elements are
-separated by this value. Default is a space. For example, this:
+separated by this value. Default is a space. For example, this:
- print "The array is: @array\n";
+ print "The array is: @array\n";
is equivalent to this:
- print "The array is: " . join($", @array) . "\n";
+ print "The array is: " . join($", @array) . "\n";
Mnemonic: works in double-quoted context.
@@ -185,16 +193,28 @@ Mnemonic: works in double-quoted context.
=item $$
X<$$> X<$PID> X<$PROCESS_ID>
-The process number of the Perl running this script. Though you I set
+The process number of the Perl running this script. Though you I set
this variable, doing so is generally discouraged, although it can be
-invaluable for some testing purposes. It will be reset automatically
+invaluable for some testing purposes. It will be reset automatically
across C calls.
-Note for Linux users: on Linux, the C functions C and
-C return different values from different threads. In order to
-be portable, this behavior is not reflected by C<$$>, whose value remains
-consistent across threads. If you want to call the underlying C,
-you may use the CPAN module C.
+Note for Linux and Debian GNU/kFreeBSD users: Before Perl v5.16.0 perl
+would emulate POSIX semantics on Linux systems using LinuxThreads, a
+partial implementation of POSIX Threads that has since been superseded
+by the Native POSIX Thread Library (NPTL).
+
+LinuxThreads is now obsolete on Linux, and caching C
+like this made embedding perl unnecessarily complex (since you'd have
+to manually update the value of $$), so now C<$$> and C
+will always return the same values as the underlying C library.
+
+Debian GNU/kFreeBSD systems also used LinuxThreads up until and
+including the 6.0 release, but after that moved to FreeBSD thread
+semantics, which are POSIX-like.
+
+To see if your system is affected by this discrepancy check if
+C returns a false
+value. NTPL threads preserve the POSIX semantics.
Mnemonic: same as shells.
@@ -206,14 +226,14 @@ X<$0> X<$PROGRAM_NAME>
Contains the name of the program being executed.
On some (but not all) operating systems assigning to C<$0> modifies
-the argument area that the C program sees. On some platforms you
+the argument area that the C program sees. On some platforms you
may have to use special C options or a different C to see the
-changes. Modifying the C<$0> is more useful as a way of indicating the
+changes. Modifying the C<$0> is more useful as a way of indicating the
current program state than it is for hiding the program you're
running.
Note that there are platform-specific limitations on the maximum
-length of C<$0>. In the most extreme case it may be limited to the
+length of C<$0>. In the most extreme case it may be limited to the
space occupied by the original C<$0>.
In some platforms there may be arbitrary amount of padding, for
@@ -223,25 +243,25 @@ length of the argument area, no matter what you do (this is the case
for example with Linux 2.2).
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"> may
+from the ps(1) output. For example, setting C<$0> to C<"foobar"> may
result in C<"perl: foobar (perl)"> (whether both the C<"perl: "> prefix
and the " (perl)" suffix are shown depends on your exact BSD variant
-and version). This is an operating system feature, Perl cannot help it.
+and version). This is an operating system feature, Perl cannot help it.
In multithreaded scripts Perl coordinates the threads so that any
thread may modify its copy of the C<$0> and the change becomes visible
-to ps(1) (assuming the operating system plays along). Note that
+to ps(1) (assuming the operating system plays along). Note that
the view of C<$0> the other threads have will not change since they
have their own copies of it.
If the program has been given to perl via the switches C<-e> or C<-E>,
C<$0> will contain the string C<"-e">.
-On Linux as of perl 5.14 the legacy process name will be set with
+On Linux as of perl v5.14.0 the legacy process name will be set with
C, in addition to altering the POSIX name via C as
-perl has done since version 4.000. Now system utilities that read the
+perl has done since version 4.000. Now system utilities that read the
legacy process name such as ps, top and killall will recognize the
-name you set when assigning to C<$0>. The string you supply will be
+name you set when assigning to C<$0>. The string you supply will be
cut off at 16 bytes, this is a limitation imposed by Linux.
Mnemonic: same as B and B.
@@ -253,23 +273,24 @@ Mnemonic: same as B and B.
=item $(
X<$(> X<$GID> X<$REAL_GROUP_ID>
-The real gid of this process. If you are on a machine that supports
+The real gid of this process. If you are on a machine that supports
membership in multiple groups simultaneously, gives a space separated
-list of groups you are in. The first number is the one returned by
+list of groups you are in. The first number is the one returned by
C, and the subsequent ones by C, one of which may be
the same as the first number.
However, a value assigned to C<$(> must be a single number used to
-set the real gid. So the value given by C<$(> should I be assigned
-back to C<$(> without being forced numeric, such as by adding zero. Note
+set the real gid. So the value given by C<$(> should I be assigned
+back to C<$(> without being forced numeric, such as by adding zero. Note
that this is different to the effective gid (C<$)>) which does take a
list.
You can change both the real gid and the effective gid at the same
-time by using C. Changes to C<$(> require a check to C<$!>
+time by using C. Changes
+to C<$(> require a check to C<$!>
to detect any possible errors after an attempted change.
-Mnemonic: parentheses are used to I things. The real gid is the
+Mnemonic: parentheses are used to I things. The real gid is the
group you I, if you're running setgid.
=item $EFFECTIVE_GROUP_ID
@@ -279,15 +300,15 @@ group you I, if you're running setgid.
=item $)
X<$)> X<$EGID> X<$EFFECTIVE_GROUP_ID>
-The effective gid of this process. If you are on a machine that
+The effective gid of this process. If you are on a machine that
supports membership in multiple groups simultaneously, gives a space
-separated list of groups you are in. The first number is the one
+separated list of groups you are in. The first number is the one
returned by C, and the subsequent ones by C,
one of which may be the same as the first number.
Similarly, a value assigned to C<$)> must also be a space-separated
-list of numbers. The first number sets the effective gid, and
-the rest (if any) are passed to C. To get the effect of an
+list of numbers. The first number sets the effective gid, and
+the rest (if any) are passed to C. To get the effect of an
empty list for C, just repeat the new effective gid; that is,
to force an effective gid of 5 and an effectively empty C
list, say C< $) = "5 5" >.
@@ -298,10 +319,10 @@ Changes to C<$)> require a check to C<$!> to detect any possible errors
after an attempted change.
C<< $< >>, C<< $> >>, C<$(> and C<$)> can be set only on
-machines that support the corresponding I routine. C<$(>
+machines that support the corresponding I routine. C<$(>
and C<$)> can be swapped only on machines supporting C.
-Mnemonic: parentheses are used to I things. The effective gid
+Mnemonic: parentheses are used to I things. The effective gid
is the group that's I for you, if you're running setgid.
=item $REAL_USER_ID
@@ -311,8 +332,8 @@ is the group that's I for you, if you're running setgid.
=item $<
X<< $< >> X<$UID> X<$REAL_USER_ID>
-The real uid of this process. You can change both the real uid and the
-effective uid at the same time by using C. Since
+The real uid of this process. You can change both the real uid and the
+effective uid at the same time by using C. Since
changes to C<< $< >> require a system call, check C<$!> after a change
attempt to detect any possible errors.
@@ -325,13 +346,13 @@ Mnemonic: it's the uid you came I, if you're running setuid.
=item $>
X<< $> >> X<$EUID> X<$EFFECTIVE_USER_ID>
-The effective uid of this process. For example:
+The effective uid of this process. For example:
- $< = $>; # set real to effective uid
- ($<,$>) = ($>,$<); # swap real and effective uids
+ $< = $>; # set real to effective uid
+ ($<,$>) = ($>,$<); # swap real and effective uids
You can change both the effective uid and the real uid at the same
-time by using C. Changes to C<< $> >> require a check
+time by using C. Changes to C<< $> >> require a check
to C<$!> to detect any possible errors after an attempted change.
C<< $< >> and C<< $> >> can be swapped only on machines
@@ -346,24 +367,24 @@ Mnemonic: it's the uid you went I, if you're running setuid.
=item $;
X<$;> X<$SUBSEP> X
-The subscript separator for multidimensional array emulation. If you
+The subscript separator for multidimensional array emulation. If you
refer to a hash element as
- $foo{$a,$b,$c}
+ $foo{$x,$y,$z}
it really means
- $foo{join($;, $a, $b, $c)}
+ $foo{join($;, $x, $y, $z)}
But don't put
- @foo{$a,$b,$c} # a slice--note the @
+ @foo{$x,$y,$z} # a slice--note the @
which means
- ($foo{$a},$foo{$b},$foo{$c})
+ ($foo{$x},$foo{$y},$foo{$z})
-Default is "\034", the same as SUBSEP in B. If your keys contain
+Default is "\034", the same as SUBSEP in B. If your keys contain
binary data there might not be any safe value for C<$;>.
Consider using "real" multidimensional arrays as described
@@ -379,26 +400,88 @@ X<$a> X<$b>
Special package variables when using C, see L.
Because of this specialness C<$a> and C<$b> don't need to be declared
(using C
match operator flag and the
-C<${^PREMATCH}>, C<${^MATCH}>, and C<${^POSTMATCH}> variables instead
-so you only suffer the performance penalties.
+ $str =~ /pattern/;
+
+ print $`, $&, $'; # bad: perfomance hit
+
+ print # good: no perfomance hit
+ substr($str, 0, $-[0]),
+ substr($str, $-[0], $+[0]-$-[0]),
+ substr($str, $+[0]);
+
+In Perl 5.10.0 the C match operator flag and the C<${^PREMATCH}>,
+C<${^MATCH}>, and C<${^POSTMATCH}> variables were introduced, that allowed
+you to suffer the penalties only on patterns marked with C.
+
+In Perl 5.18.0 onwards, perl started noting the presence of each of the
+three variables separately, and only copied that part of the string
+required; so in
+
+ $`; $&; "abcdefgh" =~ /d/
+
+perl would only copy the "abcd" part of the string. That could make a big
+difference in something like
+
+ $str = 'x' x 1_000_000;
+ $&; # whoops
+ $str =~ /x/g # one char copied a million times, not a million chars
+
+In Perl 5.20.0 a new copy-on-write system was enabled by default, which
+finally fixes all performance issues with these three variables, and makes
+them safe to use anywhere.
+
+The C and C modules can help you
+find uses of these problematic match variables in your code.
=over 8
@@ -792,11 +914,8 @@ The string matched by the last successful pattern match (not counting
any matches hidden within a BLOCK or C enclosed by the current
BLOCK).
-The use of this variable anywhere in a program imposes a considerable
-performance penalty on all regular expression matches. To avoid this
-penalty, you can extract the same substring by using L@->. Starting
-with Perl 5.10, you can use the match flag and the C<${^MATCH}>
-variable to do the same thing for particular match operations.
+See L above for the serious performance implications
+of using this variable (even once) in your code.
This variable is read-only and dynamically-scoped.
@@ -806,11 +925,16 @@ Mnemonic: like C<&> in some editors.
X<${^MATCH}>
This is similar to C<$&> (C<$MATCH>) except that it does not incur the
-performance penalty associated with that variable, and is only guaranteed
+performance penalty associated with that variable.
+
+See L above.
+
+In Perl v5.18 and earlier, it is only guaranteed
to return a defined value when the pattern was compiled or executed with
-the C modifier.
+the C modifier. In Perl v5.20, the C modifier does nothing, so
+C<${^MATCH}> does the same thing as C<$MATCH>.
-This variable was added in Perl 5.10.
+This variable was added in Perl v5.10.0.
This variable is read-only and dynamically-scoped.
@@ -823,12 +947,8 @@ The string preceding whatever was matched by the last successful
pattern match, not counting any matches hidden within a BLOCK or C
enclosed by the current BLOCK.
-The use of this variable anywhere in a program imposes a considerable
-performance penalty on all regular expression matches. To avoid this
-penalty, you can extract the same substring by using L@->. Starting
-with Perl 5.10, you can use the match flag and the
-C<${^PREMATCH}> variable to do the same thing for particular match
-operations.
+See L above for the serious performance implications
+of using this variable (even once) in your code.
This variable is read-only and dynamically-scoped.
@@ -838,11 +958,16 @@ Mnemonic: C<`> often precedes a quoted string.
X<$`> X<${^PREMATCH}>
This is similar to C<$`> ($PREMATCH) except that it does not incur the
-performance penalty associated with that variable, and is only guaranteed
+performance penalty associated with that variable.
+
+See L above.
+
+In Perl v5.18 and earlier, it is only guaranteed
to return a defined value when the pattern was compiled or executed with
-the C modifier.
+the C modifier. In Perl v5.20, the C modifier does nothing, so
+C<${^PREMATCH}> does the same thing as C<$PREMATCH>.
-This variable was added in Perl 5.10
+This variable was added in Perl v5.10.0.
This variable is read-only and dynamically-scoped.
@@ -853,18 +978,14 @@ X<$'> X<$POSTMATCH> X<${^POSTMATCH}> X<@->
The string following whatever was matched by the last successful
pattern match (not counting any matches hidden within a BLOCK or C
-enclosed by the current BLOCK). Example:
+enclosed by the current BLOCK). Example:
- local $_ = 'abcdefghi';
- /def/;
- print "$`:$&:$'\n"; # prints abc:def:ghi
+ local $_ = 'abcdefghi';
+ /def/;
+ print "$`:$&:$'\n"; # prints abc:def:ghi
-The use of this variable anywhere in a program imposes a considerable
-performance penalty on all regular expression matches.
-To avoid this penalty, you can extract the same substring by
-using L@->. Starting with Perl 5.10, you can use the match flag
-and the C<${^POSTMATCH}> variable to do the same thing for particular
-match operations.
+See L above for the serious performance implications
+of using this variable (even once) in your code.
This variable is read-only and dynamically-scoped.
@@ -874,11 +995,16 @@ Mnemonic: C<'> often follows a quoted string.
X<${^POSTMATCH}> X<$'> X<$POSTMATCH>
This is similar to C<$'> (C<$POSTMATCH>) except that it does not incur the
-performance penalty associated with that variable, and is only guaranteed
+performance penalty associated with that variable.
+
+See L above.
+
+In Perl v5.18 and earlier, it is only guaranteed
to return a defined value when the pattern was compiled or executed with
-the C modifier.
+the C modifier. In Perl v5.20, the C modifier does nothing, so
+C<${^POSTMATCH}> does the same thing as C<$POSTMATCH>.
-This variable was added in Perl 5.10.
+This variable was added in Perl v5.10.0.
This variable is read-only and dynamically-scoped.
@@ -889,9 +1015,9 @@ X<$+> X<$LAST_PAREN_MATCH>
The text matched by the last bracket of the last successful search pattern.
This is useful if you don't know which one of a set of alternative patterns
-matched. For example:
+matched. For example:
- /Version: (.*)|Revision: (.*)/ && ($rev = $+);
+ /Version: (.*)|Revision: (.*)/ && ($rev = $+);
This variable is read-only and dynamically-scoped.
@@ -907,15 +1033,15 @@ with the rightmost closing parenthesis) of the last successful search
pattern.
This is primarily used inside C<(?{...})> blocks for examining text
-recently matched. For example, to effectively capture text to a variable
+recently matched. For example, to effectively capture text to a variable
(in addition to C<$1>, C<$2>, etc.), replace C<(...)> with
- (?:(...)(?{ $var = $^N }))
+ (?:(...)(?{ $var = $^N }))
By setting and then using C<$var> in this way relieves you from having to
worry about exactly which numbered set of parentheses they are.
-This variable was added in Perl 5.8.
+This variable was added in Perl v5.8.0.
Mnemonic: the (possibly) Nested parenthesis that most recently closed.
@@ -925,17 +1051,17 @@ Mnemonic: the (possibly) Nested parenthesis that most recently closed.
X<@+> X<@LAST_MATCH_END>
This array holds the offsets of the ends of the last successful
-submatches in the currently active dynamic scope. C<$+[0]> is
-the offset into the string of the end of the entire match. This
+submatches in the currently active dynamic scope. C<$+[0]> is
+the offset into the string of the end of the entire match. This
is the same value as what the C function returns when called
-on the variable that was matched against. The Ith element
+on the variable that was matched against. The Ith element
of this array holds the offset of the Ith submatch, so
C<$+[1]> is the offset past where C<$1> ends, C<$+[2]> the offset
-past where C<$2> ends, and so on. You can use C<$#+> to determine
-how many subgroups were in the last successful match. See the
+past where C<$2> ends, and so on. You can use C<$#+> to determine
+how many subgroups were in the last successful match. See the
examples given for the C<@-> variable.
-This variable was added in Perl 5.6.
+This variable was added in Perl v5.6.0.
=item %LAST_PAREN_MATCH
@@ -948,7 +1074,7 @@ currently active dynamic scope.
For example, C<$+{foo}> is equivalent to C<$1> after the following match:
- 'foo' =~ /(?foo)/;
+ 'foo' =~ /(?foo)/;
The keys of the C<%+> hash list only the names of buffers that have
captured (and that are thus associated to defined values).
@@ -957,12 +1083,12 @@ The underlying behaviour of C<%+> is provided by the
L module.
B C<%-> and C<%+> are tied views into a common internal hash
-associated with the last successful regular expression. Therefore mixing
+associated with the last successful regular expression. Therefore mixing
iterative access to them via C may have unpredictable results.
Likewise, if the last successful match changes, then the results may be
surprising.
-This variable was added in Perl 5.10.
+This variable was added in Perl v5.10.0.
This variable is read-only and dynamically-scoped.
@@ -976,17 +1102,17 @@ C<$-[>IC<]> is the offset of the start of the substring matched by
I-th subpattern, or undef if the subpattern did not match.
Thus, after a match against C<$_>, C<$&> coincides with C. Similarly, $I coincides with C. Similarly, $I coincides with C if C<$-[n]> is defined, and $+ coincides with
-C. One can use C<$#-> to find the last
-matched subgroup in the last successful match. Contrast with
-C<$#+>, the number of subgroups in the regular expression. Compare
+C. One can use C<$#-> to find the
+last matched subgroup in the last successful match. Contrast with
+C<$#+>, the number of subgroups in the regular expression. Compare
with C<@+>.
This array holds the offsets of the beginnings of the last
successful submatches in the currently active dynamic scope.
C<$-[0]> is the offset into the string of the beginning of the
-entire match. The Ith element of this array holds the offset
+entire match. The Ith element of this array holds the offset
of the Ith submatch, so C<$-[1]> is the offset where C<$1>
begins, C<$-[2]> the offset where C<$2> begins, and so on.
@@ -1008,15 +1134,13 @@ After a match against some variable C<$var>:
=back
-This variable was added in Perl 5.6.
-
-=item %LAST_MATCH_START
+This variable was added in Perl v5.6.0.
=item %-
-X<%-> X<%LAST_MATCH_START>
+X<%->
Similar to C<%+>, this variable allows access to the named capture groups
-in the last successful match in the currently active dynamic scope. To
+in the last successful match in the currently active dynamic scope. To
each capture group name found in the regular expression, it associates a
reference to an array containing the list of values captured by all
buffers with that name (should there be several of them), in the order
@@ -1029,7 +1153,9 @@ Here's an example:
my $ary = $-{$bufname};
foreach my $idx (0..$#$ary) {
print "\$-{$bufname}[$idx] : ",
- (defined($ary->[$idx]) ? "'$ary->[$idx]'" : "undef"),
+ (defined($ary->[$idx])
+ ? "'$ary->[$idx]'"
+ : "undef"),
"\n";
}
}
@@ -1037,10 +1163,10 @@ Here's an example:
would print out:
- $-{A}[0] : '1'
- $-{A}[1] : '3'
- $-{B}[0] : '2'
- $-{B}[1] : '4'
+ $-{A}[0] : '1'
+ $-{A}[1] : '3'
+ $-{B}[0] : '2'
+ $-{B}[1] : '4'
The keys of the C<%-> hash correspond to all buffer names found in
the regular expression.
@@ -1049,12 +1175,12 @@ The behaviour of C<%-> is implemented via the
L module.
B C<%-> and C<%+> are tied views into a common internal hash
-associated with the last successful regular expression. Therefore mixing
+associated with the last successful regular expression. Therefore mixing
iterative access to them via C may have unpredictable results.
Likewise, if the last successful match changes, then the results may be
surprising.
-This variable was added in Perl 5.10
+This variable was added in Perl v5.10.0.
This variable is read-only and dynamically-scoped.
@@ -1064,30 +1190,31 @@ This variable is read-only and dynamically-scoped.
X<$^R> X<$LAST_REGEXP_CODE_RESULT>
The result of evaluation of the last successful C<(?{ code })>
-regular expression assertion (see L). May be written to.
+regular expression assertion (see L). May be written to.
This variable was added in Perl 5.005.
=item ${^RE_DEBUG_FLAGS}
X<${^RE_DEBUG_FLAGS}>
-The current value of the regex debugging flags. Set to 0 for no debug output
-even when the C module is loaded. See L for details.
+The current value of the regex debugging flags. Set to 0 for no debug output
+even when the C module is loaded. See L for details.
-This variable was added in Perl 5.10.
+This variable was added in Perl v5.10.0.
=item ${^RE_TRIE_MAXBUF}
X<${^RE_TRIE_MAXBUF}>
Controls how certain regex optimisations are applied and how much memory they
-utilize. This value by default is 65536 which corresponds to a 512kB temporary
-cache. Set this to a higher value to trade memory for speed when matching
-large alternations. Set it to a lower value if you want the optimisations to
+utilize. This value by default is 65536 which corresponds to a 512kB
+temporary cache. Set this to a higher value to trade
+memory for speed when matching large alternations. Set
+it to a lower value if you want the optimisations to
be as conservative of memory as possible but still occur, and set it to a
negative value to prevent the optimisation and conserve the most memory.
Under normal situations this variable should be of no interest to you.
-This variable was added in Perl 5.10.
+This variable was added in Perl v5.10.0.
=back
@@ -1096,50 +1223,50 @@ This variable was added in Perl 5.10.
Variables that depend on the currently selected filehandle may be set
by calling an appropriate object method on the C object,
although this is less efficient than using the regular built-in
-variables. (Summary lines below for this contain the word HANDLE.)
+variables. (Summary lines below for this contain the word HANDLE.)
First you must say
- use IO::Handle;
+ use IO::Handle;
after which you may use either
- method HANDLE EXPR
+ method HANDLE EXPR
or more safely,
- HANDLE->method(EXPR)
+ HANDLE->method(EXPR)
-Each method returns the old value of the C attribute. The
+Each method returns the old value of the C attribute. The
methods each take an optional EXPR, which, if supplied, specifies the
-new value for the C attribute in question. If not
+new value for the C attribute in question. If not
supplied, most methods do nothing to the current value--except for
C, which will assume a 1 for you, just to be different.
Because loading in the C class is an expensive operation,
you should learn how to use the regular built-in variables.
-A few of these variables are considered "read-only". This means that
+A few of these variables are considered "read-only". This means that
if you try to assign to this variable, either directly or indirectly
through a reference, you'll raise a run-time exception.
You should be very careful when modifying the default values of most
-special variables described in this document. In most cases you want
+special variables described in this document. In most cases you want
to localize these variables before changing them, since if you don't,
the change may affect other modules which rely on the default values
-of the special variables that you have changed. This is one of the
+of the special variables that you have changed. This is one of the
correct ways to read the whole file at once:
- open my $fh, "<", "foo" or die $!;
- local $/; # enable localized slurp mode
- my $content = <$fh>;
- close $fh;
+ open my $fh, "<", "foo" or die $!;
+ local $/; # enable localized slurp mode
+ my $content = <$fh>;
+ close $fh;
But the following code is quite bad:
- open my $fh, "<", "foo" or die $!;
- undef $/; # enable slurp mode
- my $content = <$fh>;
- close $fh;
+ open my $fh, "<", "foo" or die $!;
+ undef $/; # enable slurp mode
+ my $content = <$fh>;
+ close $fh;
since some other module, may want to read data from some file in the
default "line mode", so if the code we have just presented has been
@@ -1147,30 +1274,30 @@ executed, the global value of C<$/> is now changed for any other code
running inside the same Perl interpreter.
Usually when a variable is localized you want to make sure that this
-change affects the shortest scope possible. So unless you are already
-inside some short C<{}> block, you should create one yourself. For
+change affects the shortest scope possible. So unless you are already
+inside some short C<{}> block, you should create one yourself. For
example:
- my $content = '';
- open my $fh, "<", "foo" or die $!;
- {
- local $/;
- $content = <$fh>;
- }
- close $fh;
+ my $content = '';
+ open my $fh, "<", "foo" or die $!;
+ {
+ local $/;
+ $content = <$fh>;
+ }
+ close $fh;
Here is an example of how your own code can go broken:
- for ( 1..3 ){
- $\ = "\r\n";
- nasty_break();
- print "$_";
- }
+ for ( 1..3 ){
+ $\ = "\r\n";
+ nasty_break();
+ print "$_";
+ }
- sub nasty_break {
+ sub nasty_break {
$\ = "\f";
# do something with $_
- }
+ }
You probably expect this code to print the equivalent of
@@ -1181,11 +1308,11 @@ but instead you get:
"1\f2\f3\f"
Why? Because C modifies C<$\> without localizing it
-first. The value you set in C is still there when you
-return. The fix is to add C so the value doesn't leak out of
+first. The value you set in C is still there when you
+return. The fix is to add C so the value doesn't leak out of
C:
- local $\ = "\f";
+ local $\ = "\f";
It's easy to notice the problem in such a short example, but in more
complicated code you are looking for trouble if you don't localize
@@ -1202,18 +1329,18 @@ Contains the name of the current file when reading from C<< <> >>.
X<@ARGV>
The array C<@ARGV> contains the command-line arguments intended for
-the script. C<$#ARGV> is generally the number of arguments minus
+the script. C<$#ARGV> is generally the number of arguments minus
one, because C<$ARGV[0]> is the first argument, I the program's
-command name itself. See L$0> for the command name.
+command name itself. See L$0> for the command name.
=item ARGV
X
The special filehandle that iterates over command-line filenames in
-C<@ARGV>. Usually written as the null filehandle in the angle operator
-C<< <> >>. Note that currently C only has its magical effect
+C<@ARGV>. Usually written as the null filehandle in the angle operator
+C<< <> >>. Note that currently C only has its magical effect
within the C<< <> >> operator; elsewhere it is just a plain filehandle
-corresponding to the last file opened by C<< <> >>. In particular,
+corresponding to the last file opened by C<< <> >>. In particular,
passing C<\*ARGV> as a parameter to a function that expects a filehandle
may not cause your function to automatically read the contents of all the
files in C<@ARGV>.
@@ -1222,11 +1349,11 @@ files in C<@ARGV>.
X
The special filehandle that points to the currently open output file
-when doing edit-in-place processing with B<-i>. Useful when you have
-to do a lot of inserting and don't want to keep modifying C<$_>. See
+when doing edit-in-place processing with B<-i>. Useful when you have
+to do a lot of inserting and don't want to keep modifying C<$_>. See
L for the B<-i> switch.
-=item Handle->output_field_separator( EXPR )
+=item IO::Handle->output_field_separator( EXPR )
=item $OUTPUT_FIELD_SEPARATOR
@@ -1235,8 +1362,11 @@ L for the B<-i> switch.
=item $,
X<$,> X<$OFS> X<$OUTPUT_FIELD_SEPARATOR>
-The output field separator for the print operator. If defined, this
-value is printed between each of print's arguments. Default is C.
+The output field separator for the print operator. If defined, this
+value is printed between each of print's arguments. Default is C.
+
+You cannot call C on a handle, only as a
+static method. See L.
Mnemonic: what is printed when there is a "," in your print statement.
@@ -1252,20 +1382,20 @@ X<$.> X<$NR> X<$INPUT_LINE_NUMBER> X
Current line number for the last filehandle accessed.
Each filehandle in Perl counts the number of lines that have been read
-from it. (Depending on the value of C<$/>, Perl's idea of what
+from it. (Depending on the value of C<$/>, Perl's idea of what
constitutes a line may not match yours.) When a line is read from a
filehandle (via C or C<< <> >>), or when C or
C is called on it, C<$.> becomes an alias to the line counter
for that filehandle.
You can adjust the counter by assigning to C<$.>, but this will not
-actually move the seek pointer. I will not localize
-the filehandle's line count>. Instead, it will localize perl's notion
+actually move the seek pointer. I will not localize
+the filehandle's line count>. Instead, it will localize perl's notion
of which filehandle C<$.> is currently aliased to.
C<$.> is reset when the filehandle is closed, but B when an open
-filehandle is reopened without an intervening C. For more
-details, see LO Operators">. Because C<< <> >> never does
+filehandle is reopened without an intervening C. For more
+details, see LO Operators">. Because C<< <> >> never does
an explicit close, line numbers increase across C files (but see
examples in L).
@@ -1275,7 +1405,7 @@ which handle you last accessed.
Mnemonic: many programs use "." to mean the current line number.
-=item HANDLE->input_record_separator( EXPR )
+=item IO::Handle->input_record_separator( EXPR )
=item $INPUT_RECORD_SEPARATOR
@@ -1284,15 +1414,15 @@ Mnemonic: many programs use "." to mean the current line number.
=item $/
X<$/> X<$RS> X<$INPUT_RECORD_SEPARATOR>
-The input record separator, newline by default. This influences Perl's
-idea of what a "line" is. Works like B's RS variable, including
+The input record separator, newline by default. This influences Perl's
+idea of what a "line" is. Works like B's RS variable, including
treating empty lines as a terminator if set to the null string (an
-empty line cannot contain any spaces or tabs). You may set it to a
+empty line cannot contain any spaces or tabs). You may set it to a
multi-character string to match a multi-character terminator, or to
-C to read through the end of file. Setting it to C<"\n\n">
+C to read through the end of file. Setting it to C<"\n\n">
means something slightly different than setting to C<"">, if the file
-contains consecutive empty lines. Setting to C<""> will treat two or
-more consecutive empty lines as a single empty line. Setting to
+contains consecutive empty lines. Setting to C<""> will treat two or
+more consecutive empty lines as a single empty line. Setting to
C<"\n\n"> will blindly assume that the next input character belongs to
the next paragraph, even if it's a newline.
@@ -1300,37 +1430,43 @@ the next paragraph, even if it's a newline.
local $_ = ; # whole file now here
s/\n[ \t]+/ /g;
-Remember: the value of C<$/> is a string, not a regex. B has to
+Remember: the value of C<$/> is a string, not a regex. B has to
be better for something. :-)
Setting C<$/> to a reference to an integer, scalar containing an
integer, or scalar that's convertible to an integer will attempt to
read records instead of lines, with the maximum record size being the
-referenced integer. So this:
+referenced integer number of characters. So this:
local $/ = \32768; # or \"32768", or \$var_containing_32768
open my $fh, "<", $myfile or die $!;
local $_ = <$fh>;
-will read a record of no more than 32768 bytes from FILE. If you're
+will read a record of no more than 32768 characters from $fh. If you're
not reading from a record-oriented file (or your OS doesn't have
record-oriented files), then you'll likely get a full chunk of data
-with every read. If a record is larger than the record size you've
-set, you'll get the record back in pieces. Trying to set the record
-size to zero or less will cause reading in the (rest of the) whole file.
+with every read. If a record is larger than the record size you've
+set, you'll get the record back in pieces. Trying to set the record
+size to zero or less is deprecated and will cause $/ to have the value
+of "undef", which will cause reading in the (rest of the) whole file.
-On VMS, record reads are done with the equivalent of C,
-so it's best not to mix record and non-record reads on the same
-file. (This is unlikely to be a problem, because any file you'd
-want to read in record mode is probably unusable in line mode.)
-Non-VMS systems do normal I/O, so it's safe to mix record and
-non-record reads of a file.
+As of 5.19.9 setting C<$/> to any other form of reference will throw a
+fatal exception. This is in preparation for supporting new ways to set
+C<$/> in the future.
-See also L. Also see L$.>.
+On VMS only, record reads bypass PerlIO layers and any associated
+buffering, so you must not mix record and non-record reads on the
+same filehandle. Record mode mixes with line mode only when the
+same buffering layer is in use for both modes.
+
+You cannot call C on a handle, only as a
+static method. See L.
+
+See also L. Also see L$.>.
Mnemonic: / delimits line boundaries when quoting poetry.
-=item Handle->output_record_separator( EXPR )
+=item IO::Handle->output_record_separator( EXPR )
=item $OUTPUT_RECORD_SEPARATOR
@@ -1339,8 +1475,11 @@ Mnemonic: / delimits line boundaries when quoting poetry.
=item $\
X<$\> X<$ORS> X<$OUTPUT_RECORD_SEPARATOR>
-The output record separator for the print operator. If defined, this
-value is printed after the last of print's arguments. Default is C.
+The output record separator for the print operator. If defined, this
+value is printed after the last of print's arguments. Default is C.
+
+You cannot call C on a handle, only as a
+static method. See L.
Mnemonic: you set C<$\> instead of adding "\n" at the end of the print.
Also, it's just like C<$/>, but it's what you get "back" from Perl.
@@ -1353,25 +1492,36 @@ Also, it's just like C<$/>, but it's what you get "back" from Perl.
X<$|> X X X<$OUTPUT_AUTOFLUSH>
If set to nonzero, forces a flush right away and after every write or
-print on the currently selected output channel. Default is 0
+print on the currently selected output channel. Default is 0
(regardless of whether the channel is really buffered by the system or
not; C<$|> tells you only whether you've asked Perl explicitly to
-flush after each write). STDOUT will typically be line buffered if
-output is to the terminal and block buffered otherwise. Setting this
+flush after each write). STDOUT will typically be line buffered if
+output is to the terminal and block buffered otherwise. Setting this
variable is useful primarily when you are outputting to a pipe or
socket, such as when you are running a Perl program under B and
-want to see the output as it's happening. This has no effect on input
-buffering. See L for that. See L on
-how to select the output channel. See also L.
+want to see the output as it's happening. This has no effect on input
+buffering. See L for that. See L on
+how to select the output channel. See also L.
Mnemonic: when you want your pipes to be piping hot.
+=item ${^LAST_FH}
+X<${^LAST_FH}>
+
+This read-only variable contains a reference to the last-read filehandle.
+This is set by C<< >>, C, C, C and C.
+This is the same handle that C<$.> and C and C without arguments
+use. It is also the handle used when Perl appends ", line 1" to
+an error or warning message.
+
+This variable was added in Perl v5.18.0.
+
=back
=head3 Variables related to formats
The special variables for formats are a subset of those for
-filehandles. See L for more information about Perl's
+filehandles. See L for more information about Perl's
formats.
=over 8
@@ -1383,19 +1533,22 @@ X<$^A> X<$ACCUMULATOR>
The current value of the C accumulator for C lines.
A format contains C calls that put their result into
-C<$^A>. After calling its format, C prints out the contents
-of C<$^A> and empties. So you never really see the contents of C<$^A>
-unless you call C yourself and then look at it. See
+C<$^A>. After calling its format, C prints out the contents
+of C<$^A> and empties. So you never really see the contents of C<$^A>
+unless you call C yourself and then look at it. See
L and L.
-=item HANDLE->format_formfeed(EXPR)
+=item IO::Handle->format_formfeed(EXPR)
=item $FORMAT_FORMFEED
=item $^L
X<$^L> X<$FORMAT_FORMFEED>
-What formats output as a form feed. The default is C<\f>.
+What formats output as a form feed. The default is C<\f>.
+
+You cannot call C on a handle, only as a static
+method. See L.
=item HANDLE->format_page_number(EXPR)
@@ -1420,7 +1573,7 @@ channel.
Mnemonic: lines_on_page - lines_printed.
-=item Handle->format_line_break_characters EXPR
+=item IO::Handle->format_line_break_characters EXPR
=item $FORMAT_LINE_BREAK_CHARACTERS
@@ -1428,9 +1581,12 @@ Mnemonic: lines_on_page - lines_printed.
X<$:> X
The current set of characters after which a string may be broken to
-fill continuation fields (starting with C<^>) in a format. The default is
+fill continuation fields (starting with C<^>) in a format. The default is
S<" \n-">, to break on a space, newline, or a hyphen.
+You cannot call C on a handle, only as
+a static method. See L.
+
Mnemonic: a "colon" in poetry is a part of a line.
=item HANDLE->format_lines_per_page(EXPR)
@@ -1441,7 +1597,7 @@ Mnemonic: a "colon" in poetry is a part of a line.
X<$=> X<$FORMAT_LINES_PER_PAGE>
The current page length (printable lines) of the currently selected
-output channel. The default is 60.
+output channel. The default is 60.
Mnemonic: = has horizontal lines.
@@ -1453,9 +1609,9 @@ Mnemonic: = has horizontal lines.
X<$^> X<$FORMAT_TOP_NAME>
The name of the current top-of-page format for the currently selected
-output channel. The default is the name of the filehandle with C<_TOP>
-appended. For example, the default format top name for the C
-filehanlde is C.
+output channel. The default is the name of the filehandle with C<_TOP>
+appended. For example, the default format top name for the C
+filehandle is C.
Mnemonic: points to top of page.
@@ -1467,8 +1623,8 @@ Mnemonic: points to top of page.
X<$~> X<$FORMAT_NAME>
The name of the current report format for the currently selected
-output channel. The default format name is the same as the filehandle
-name. For example, the default format name for the C
+output channel. The default format name is the same as the filehandle
+name. For example, the default format name for the C
filehandle is just C.
Mnemonic: brother to C<$^>.
@@ -1480,46 +1636,46 @@ X X
The variables C<$@>, C<$!>, C<$^E>, and C<$?> contain information
about different types of error conditions that may appear during
-execution of a Perl program. The variables are shown ordered by
+execution of a Perl program. The variables are shown ordered by
the "distance" between the subsystem which reported the error and
-the Perl process. They correspond to errors detected by the Perl
+the Perl process. They 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, which uses a single-quoted string. After
+following Perl expression, which uses a single-quoted string. After
execution of this statement, perl may have set all four special error
variables:
- eval q{
- open my $pipe, "/cdrom/install |" or die $!;
- my @res = <$pipe>;
- close $pipe or die "bad pipe: $?, $!";
- };
+ eval q{
+ open my $pipe, "/cdrom/install |" or die $!;
+ my @res = <$pipe>;
+ close $pipe or die "bad pipe: $?, $!";
+ };
When perl executes the C expression, it translates the
C, C<< >>, and C calls in the C run-time library
-and thence to the operating system kernel. perl sets C<$!> to
+and thence to the operating system kernel. perl sets C<$!> to
the C library's C if one of these calls fails.
C<$@> is set if the string to be C-ed did not compile (this may
happen if C or C were imported with bad prototypes), or
-if Perl code executed during evaluation Cd. In these cases the
+if Perl code executed during evaluation Cd. In these cases the
value of C<$@> is the compile error, or the argument to C (which
-will interpolate C<$!> and C<$?>). (See also L, though.)
+will interpolate C<$!> and C<$?>). (See also L, though.)
Under a few operating systems, C<$^E> may contain a more verbose error
-indicator, such as in this case, "CDROM tray not closed." Systems that
+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 program
-F fails. The upper eight bits reflect specific error
+Finally, C<$?> may be set to a non-0 value if the external program
+F fails. The upper eight bits reflect specific error
conditions encountered by the program (the program's C value).
The lower eight bits reflect mode of failure, like signal death and
-core dump information. See L for details. In contrast to
-C<$!> and C<$^E>, which are set only if error condition is detected,
+core dump information. See L for details. In contrast to
+C<$!> and C<$^E>, which are set only if an error condition is detected,
the variable C<$?> is set on each C or pipe C,
-overwriting the old value. This is more like C<$@>, which on every
+overwriting the old value. This is more like C<$@>, which on every
C is always set on failure and cleared on success.
For more details, see the individual descriptions at C<$@>, C<$!>,
@@ -1532,28 +1688,28 @@ X<$^CHILD_ERROR_NATIVE>
The native status returned by the last pipe close, backtick (C<``>)
command, successful call to C or C, or from the
-C operator. On POSIX-like systems this value can be decoded
+C operator. On POSIX-like systems this value can be decoded
with the WIFEXITED, WEXITSTATUS, WIFSIGNALED, WTERMSIG, WIFSTOPPED,
WSTOPSIG and WIFCONTINUED functions provided by the L module.
Under VMS this reflects the actual VMS exit status; i.e. it is the
same as C<$?> when the pragma C is in effect.
-This variable was added in Perl 5.8.9.
+This variable was added in Perl v5.10.0.
=item $EXTENDED_OS_ERROR
=item $^E
X<$^E> X<$EXTENDED_OS_ERROR>
-Error information specific to the current operating system. At the
-moment, this differs from C<$!> under only VMS, OS/2, and Win32 (and
-for MacPerl). On all other platforms, C<$^E> is always just the same
+Error information specific to the current operating system. At the
+moment, this differs from C> under only VMS, OS/2, and Win32 (and
+for MacPerl). On all other platforms, C<$^E> is always just the same
as C<$!>.
Under VMS, C<$^E> provides the VMS status value from the last system
-error. This is more specific information about the last system error
-than that provided by C<$!>. This is particularly important when C<$!>
+error. This is more specific information about the last system error
+than that provided by C<$!>. This is particularly important when C<$!>
is set to B.
Under OS/2, C<$^E> is set to the error code of the last call to OS/2
@@ -1561,11 +1717,11 @@ API either via CRT, or directly from perl.
Under Win32, C<$^E> always returns the last error information reported
by the Win32 call C which describes the last error
-from within the Win32 API. Most Win32-specific code will report errors
-via C<$^E>. ANSI C and Unix-like calls set C and so most
+from within the Win32 API. Most Win32-specific code will report errors
+via C<$^E>. ANSI C and Unix-like calls set C and so most
portable Perl code will report errors via C<$!>.
-Caveats mentioned in the description of C<$!> generally apply to
+Caveats mentioned in the description of C> generally apply to
C<$^E>, also.
This variable was added in Perl 5.003.
@@ -1580,14 +1736,18 @@ X<$^S> X<$EXCEPTIONS_BEING_CAUGHT>
Current state of the interpreter.
$^S State
- --------- -------------------
- undef Parsing module/eval
+ --------- -------------------------------------
+ undef Parsing module, eval, or main program
true (1) Executing an eval
false (0) Otherwise
The first state may happen in C<$SIG{__DIE__}> and C<$SIG{__WARN__}>
handlers.
+The English name $EXCEPTIONS_BEING_CAUGHT is slightly misleading, because
+the C value does not indicate whether exceptions are being caught,
+since compilation of the main program does not catch exceptions.
+
This variable was added in Perl 5.004.
=item $WARNING
@@ -1606,9 +1766,11 @@ Mnemonic: related to the B<-w> switch.
X<${^WARNING_BITS}>
The current set of warning checks enabled by the C pragma.
-See the documentation of C for more details.
+It has the same scoping as the C<$^H> and C<%^H> variables. The exact
+values are considered internal to the L pragma and may change
+between versions of Perl.
-This variable was added in Perl 5.10.
+This variable was added in Perl v5.6.0.
=item $OS_ERROR
@@ -1656,13 +1818,15 @@ Mnemonic: What just went bang?
X<%!> X<%OS_ERROR> X<%ERRNO>
Each element of C<%!> has a true value only if C<$!> is set to that
-value. For example, C<$!{ENOENT}> is true if and only if the current
+value. For example, C<$!{ENOENT}> is true if and only if the current
value of C<$!> is C; that is, if the most recent error was "No
such file or directory" (or its moral equivalent: not all operating
-systems give that exact error, and certainly not all languages). To
-check if a particular key is meaningful on your system, use C; for a list of legal keys, use C. See L
-for more information, and also see L$!>.
+systems give that exact error, and certainly not all languages). The
+specific true value is not guaranteed, but in the past has generally
+been the numeric value of C<$!>. To check if a particular key is
+meaningful on your system, use C; for a list of legal
+keys, use C. See L for more information, and also see
+L$!>.
This variable was added in Perl 5.005.
@@ -1673,9 +1837,9 @@ X<$?> X<$CHILD_ERROR>
The status returned by the last pipe close, backtick (C<``>) command,
successful call to C or C, or from the C
-operator. This is just the 16-bit status word returned by the
+operator. This is just the 16-bit status word returned by the
traditional Unix C system call (or else is made up to look
-like it). Thus, the exit value of the subprocess is really (C<<< $? >>
+like it). Thus, the exit value of the subprocess is really (C<<< $? >>
8 >>>), and C<$? & 127> gives which signal, if any, the process died
from, and C<$? & 128> reports whether there was a core dump.
@@ -1686,8 +1850,8 @@ If you have installed a signal handler for C, the
value of C<$?> will usually be wrong outside that handler.
Inside an C subroutine C<$?> contains the value that is going to be
-given to C. You can modify C<$?> in an C subroutine to
-change the exit status of your program. For example:
+given to C. You can modify C<$?> in an C subroutine to
+change the exit status of your program. For example:
END {
$? = 1 if $? == 255; # die would make it 255
@@ -1704,16 +1868,18 @@ Mnemonic: similar to B and B.
=item $@
X<$@> X<$EVAL_ERROR>
-The Perl syntax error message from the last C operator. If C<$@> is
-the null string, the last C parsed and executed correctly
-(although the operations you invoked may have failed in the normal
-fashion).
+The Perl error from the last C operator, i.e. the last exception that
+was caught. For C, this is either a runtime error message or the
+string or reference C was called with. The C form also
+catches syntax errors and other compile time exceptions.
-Warning messages are not collected in this variable. You can, however,
+If no error occurs, C sets C<$@> to the empty string.
+
+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 in L%SIG>.
-Mnemonic: Where was the syntax error "at"?
+Mnemonic: Where was the error "at"?
=back
@@ -1731,31 +1897,52 @@ X<$^C> X<$COMPILING>
The current value of the flag associated with the B<-c> switch.
Mainly of use with B<-MO=...> to allow code to alter its behavior
when being compiled, such as for example to C at compile
-time rather than normal, deferred loading. Setting
+time rather than normal, deferred loading. Setting
C<$^C = 1> is similar to calling C.
-This variable was added in Perl 5.6.
+This variable was added in Perl v5.6.0.
=item $DEBUGGING
=item $^D
X<$^D> X<$DEBUGGING>
-The current value of the debugging flags. May be read or set. Like its
-command-line equivalent, you can use numeric or symbolic values, eg
-C<$^D = 10> or C<$^D = "st">.
+The current value of the debugging flags. May be read or set. Like its
+LI>, you can use numeric
+or symbolic values, e.g. C<$^D = 10> or C<$^D = "st">. See
+LI>. The contents of this variable also affects the
+debugger operation. See L.
Mnemonic: value of B<-D> switch.
=item ${^ENCODING}
X<${^ENCODING}>
-The I