X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/d7c042c9f3475e045bbea4f4880efff973b7049d..2cb35ee012cfe486aa75a422e7bb3cb18ff51336:/pod/perlvar.pod diff --git a/pod/perlvar.pod b/pod/perlvar.pod index eb7468f..257fdb6 100644 --- a/pod/perlvar.pod +++ b/pod/perlvar.pod @@ -12,40 +12,40 @@ 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<'> 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. -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 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 @@ -57,15 +57,11 @@ 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: - - use English '-no_match_vars'; +borrowed from B. For more info, please see L. Before you continue, note the sort order for variables. In general, we first list the variables in case-insensitive, almost-lexigraphical @@ -86,17 +82,17 @@ X<$_> X<$ARG> 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: @@ -107,10 +103,11 @@ 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, evalbytes, exp, glob, -hex, int, lc, lcfirst, length, log, lstat, mkdir, oct, ord, pos, print, +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 * @@ -138,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. =back -As C<$_> is a global variable, this may lead in some cases to unwanted -side-effects. As of perl 5.10, you can now use a lexical version of +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. +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. @@ -158,7 +165,7 @@ 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. +the array operators C and C. See L. @@ -171,11 +178,11 @@ 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: - 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. @@ -196,7 +203,7 @@ 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 and caching C +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. @@ -207,7 +214,7 @@ 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. +value. NTPL threads preserve the POSIX semantics. Mnemonic: same as shells. @@ -250,7 +257,7 @@ 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 legacy process name such as ps, top and killall will recognize the @@ -341,8 +348,8 @@ X<< $> >> X<$EUID> X<$EFFECTIVE_USER_ID> 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 @@ -363,19 +370,19 @@ X<$;> X<$SUBSEP> X 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 binary data there might not be any safe value for C<$;>. @@ -403,6 +410,67 @@ The hash C<%ENV> contains your current environment. Setting a value in C changes the environment for any child processes you subsequently C off. +As of v5.18.0, both keys and values stored in C<%ENV> are stringified. + + my $foo = 1; + $ENV{'bar'} = \$foo; + if( ref $ENV{'bar'} ) { + say "Pre 5.18.0 Behaviour"; + } else { + say "Post 5.18.0 Behaviour"; + } + +Previously, only child processes received stringified values: + + my $foo = 1; + $ENV{'bar'} = \$foo; + + # Always printed 'non ref' + system($^X, '-e', + q/print ( ref $ENV{'bar'} ? 'ref' : 'non ref' ) /); + +This happens because you can't really share arbitrary data structures with +foreign processes. + +=item $OLD_PERL_VERSION + +=item $] +X<$]> X<$OLD_PERL_VERSION> + +The revision, version, and subversion of the Perl interpreter, represented +as a decimal of the form 5.XXXYYY, where XXX is the version / 1e3 and YYY +is the subversion / 1e6. For example, Perl v5.10.1 would be "5.010001". + +This variable can be used to determine whether the Perl interpreter +executing a script is in the right range of versions: + + warn "No PerlIO!\n" if $] lt '5.008'; + +When comparing C<$]>, string comparison operators are B. The inherent limitations of binary floating point +representation can sometimes lead to incorrect comparisons for some +numbers on some architectures. + +See also the documentation of C and C +for a convenient way to fail if the running Perl interpreter is too old. + +See L for a representation of the Perl version as a L +object, which allows more flexible string comparisons. + +The main advantage of C<$]> over C<$^V> is that it works the same on any +version of Perl. The disadvantages are that it can't easily be compared +to versions in other formats (e.g. literal v-strings, "v1.2.3" or +version objects) and numeric comparisons can occasionally fail; it's good +for string literal version checks and bad for comparing to a variable +that hasn't been sanity-checked. + +The C<$OLD_PERL_VERSION> form was added in Perl v5.20.0 for historical +reasons but its use is discouraged. (If your reason to use C<$]> is to +run code on old perls then referring to it as C<$OLD_PERL_VERSION> would +be self-defeating.) + +Mnemonic: Is this version of perl in the right bracket? + =item $SYSTEM_FD_MAX =item $^F @@ -435,12 +503,13 @@ initially consists of the arguments to any B<-I> command-line switches, followed by the default Perl library, probably F, followed by ".", to represent the current directory. ("." will not be appended if taint checks are enabled, -either by C<-T> or by C<-t>.) If you need to modify this at runtime, -you should use the C pragma to get the machine-dependent -library properly loaded also: +either by C<-T> or by C<-t>, or if configured not to do so by the +C<-Ddefault_inc_excludes_dot> compile time option.) If you need to +modify this at runtime, you should use the C pragma to get +the machine-dependent library properly loaded also: - use lib '/mypath/libdir/'; - use SomeMod; + use lib '/mypath/libdir/'; + use SomeMod; You can also insert hooks into the file inclusion system by putting Perl code directly into C<@INC>. Those hooks may be subroutine references, @@ -472,6 +541,19 @@ inplace editing. Mnemonic: value of B<-i> switch. +=item @ISA +X<@ISA> + +Each package contains a special array called C<@ISA> which contains a list +of that class's parent classes, if any. This array is simply a list of +scalars, each of which is a string that corresponds to a package name. The +array is examined when Perl does method resolution, which is covered in +L. + +To load packages while adding them to C<@ISA>, see the L pragma. The +discouraged L pragma does this as well, but should not be used except +when compatibility with the discouraged L pragma is required. + =item $^M X<$^M> @@ -481,7 +563,7 @@ as an emergency memory pool after Cing. Suppose that your Perl were compiled with C<-DPERL_EMERGENCY_SBRK> and used Perl's malloc. Then - $^M = 'a' x (1 << 16); + $^M = 'a' x (1 << 16); would allocate a 64K buffer for use in an emergency. See the F file in the Perl distribution for information on how to @@ -516,18 +598,18 @@ X<%SIG> The hash C<%SIG> contains signal handlers for signals. For example: - sub handler { # 1st argument is signal name - my($sig) = @_; - print "Caught a SIG$sig--shutting down\n"; - close(LOG); - exit(0); - } + sub handler { # 1st argument is signal name + my($sig) = @_; + print "Caught a SIG$sig--shutting down\n"; + close(LOG); + exit(0); + } - $SIG{'INT'} = \&handler; - $SIG{'QUIT'} = \&handler; - ... - $SIG{'INT'} = 'DEFAULT'; # restore default action - $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT + $SIG{'INT'} = \&handler; + $SIG{'QUIT'} = \&handler; + ... + $SIG{'INT'} = 'DEFAULT'; # restore default action + $SIG{'QUIT'} = 'IGNORE'; # ignore SIGQUIT Using a value of C<'IGNORE'> usually has the effect of ignoring the signal, except for the C signal. See L for more about @@ -535,10 +617,13 @@ this special case. Here are some other examples: - $SIG{"PIPE"} = "Plumber"; # assumes main::Plumber (not recommended) - $SIG{"PIPE"} = \&Plumber; # just fine; assume current Plumber - $SIG{"PIPE"} = *Plumber; # somewhat esoteric - $SIG{"PIPE"} = Plumber(); # oops, what did Plumber() return?? + $SIG{"PIPE"} = "Plumber"; # assumes main::Plumber (not + # recommended) + $SIG{"PIPE"} = \&Plumber; # just fine; assume current + # Plumber + $SIG{"PIPE"} = *Plumber; # somewhat esoteric + $SIG{"PIPE"} = Plumber(); # oops, what did Plumber() + # return?? Be sure not to use a bareword as the name of a signal handler, lest you inadvertently call it. @@ -546,7 +631,7 @@ lest you inadvertently call it. If your system has the C function then signal handlers are installed using it. This means you get reliable signal handling. -The default delivery policy of signals changed in Perl 5.8.0 from +The default delivery policy of signals changed in Perl v5.8.0 from immediate (also known as "unsafe") to deferred, also known as "safe signals". See L for more information. @@ -558,13 +643,13 @@ ordinary printing of warnings to C to be suppressed. You can use this to save warnings in a variable, or turn warnings into fatal errors, like this: - local $SIG{__WARN__} = sub { die $_[0] }; - eval $proggie; + local $SIG{__WARN__} = sub { die $_[0] }; + eval $proggie; As the C<'IGNORE'> hook is not supported by C<__WARN__>, you can disable warnings using the empty subroutine: - local $SIG{__WARN__} = sub {}; + local $SIG{__WARN__} = sub {}; The routine indicated by C<$SIG{__DIE__}> is called when a fatal exception is about to be thrown. The error message is passed as the @@ -575,13 +660,12 @@ or a C. The C<__DIE__> handler is explicitly disabled during the call, so that you can die from a C<__DIE__> handler. Similarly for C<__WARN__>. -Due to an implementation glitch, the C<$SIG{__DIE__}> hook is called -even inside an C. Do not use this to rewrite a pending -exception in C<$@>, or as a bizarre substitute for overriding -C. This strange action at a distance may be fixed -in a future release so that C<$SIG{__DIE__}> is only called if your -program is about to exit, as was the original intent. Any other use is -deprecated. +The C<$SIG{__DIE__}> hook is called even inside an C. It was +never intended to happen this way, but an implementation glitch made +this possible. This used to be deprecated, as it allowed strange action +at a distance like rewriting a pending exception in C<$@>. Plans to +rectify this have been scrapped, as users found that rewriting a +pending exception is actually a useful feature, and not a bug. C<__DIE__>/C<__WARN__> handlers are very special in one respect: they may be called to report (probable) errors found by the parser. In such @@ -590,10 +674,11 @@ evaluate Perl code from such a handler will probably result in a segfault. This means that warnings or errors that result from parsing Perl should be used with extreme caution, like this: - require Carp if defined $^S; - Carp::confess("Something wrong") if defined &Carp::confess; - die "Something wrong, but could not load Carp to give backtrace... - To see backtrace try starting Perl with -MCarp switch"; + require Carp if defined $^S; + Carp::confess("Something wrong") if defined &Carp::confess; + die "Something wrong, but could not load Carp to give " + . "backtrace...\n\t" + . "To see backtrace try starting Perl with -MCarp switch"; Here the first line will load C I it is the parser who called the handler. The second line will print backtrace and die if @@ -623,30 +708,36 @@ and B<-C> filetests are based on this value. X<$^V> X<$PERL_VERSION> The revision, version, and subversion of the Perl interpreter, -represented as a C object. +represented as a L object. -This variable first appeared in perl 5.6.0; earlier versions of perl -will see an undefined value. Before perl 5.10.0 C<$^V> was represented -as a v-string. +This variable first appeared in perl v5.6.0; earlier versions of perl +will see an undefined value. Before perl v5.10.0 C<$^V> was represented +as a v-string rather than a L object. C<$^V> can be used to determine whether the Perl interpreter executing a script is in the right range of versions. For example: - warn "Hashes not randomized!\n" if !$^V or $^V lt v5.8.1 + warn "Hashes not randomized!\n" if !$^V or $^V lt v5.8.1 -To convert C<$^V> into its string representation use C's -C<"%vd"> conversion: +While version objects overload stringification, to portably convert +C<$^V> into its string representation, use C's C<"%vd"> +conversion, which works for both v-strings or version objects: - printf "version is v%vd\n", $^V; # Perl's version + printf "version is v%vd\n", $^V; # Perl's version See the documentation of C and C for a convenient way to fail if the running Perl interpreter is too old. -See also C<$]> for an older representation of the Perl version. +See also C> for a decimal representation of the Perl version. -This variable was added in Perl 5.6. +The main advantage of C<$^V> over C<$]> is that, for Perl v5.10.0 or +later, it overloads operators, allowing easy comparison against other +version representations (e.g. decimal, literal v-string, "v1.2.3", or +objects). The disadvantage is that prior to v5.10.0, it was only a +literal v-string, which can't be easily printed or compared, whereas +the behavior of C<$]> is unchanged on all versions of Perl. -Mnemonic: use ^V for Version Control. +Mnemonic: use ^V for a version object. =item ${^WIN32_SLOPPY_STAT} X<${^WIN32_SLOPPY_STAT}> X X @@ -663,7 +754,7 @@ default. See the documentation for B<-f> in L for more information about site customization. -This variable was added in Perl 5.10. +This variable was added in Perl v5.10.0. =item $EXECUTABLE_NAME @@ -684,7 +775,7 @@ value may or may not include a version number. You usually can use the value of C<$^X> to re-invoke an independent copy of the same perl that is currently running, e.g., - @first_run = `$^X -le "print int rand 100 for 1..100"`; + @first_run = `$^X -le "print int rand 100 for 1..100"`; But recall that not all operating systems support forking or capturing of the output of commands, so this complex statement @@ -696,13 +787,13 @@ executable files do not require use of the suffix when invoking a command. To convert the value of C<$^X> to a path name, use the following statements: - # Build up a set of file names (not command names). - use Config; - my $this_perl = $^X; - if ($^O ne 'VMS') { - $this_perl .= $Config{_exe} - unless $this_perl =~ m/$Config{_exe}$/i; - } + # Build up a set of file names (not command names). + use Config; + my $this_perl = $^X; + if ($^O ne 'VMS') { + $this_perl .= $Config{_exe} + unless $this_perl =~ m/$Config{_exe}$/i; + } Because many operating systems permit anyone with read access to the Perl program file to make a copy of it, patch the copy, and @@ -712,12 +803,12 @@ copy referenced by C<$^X>. The following statements accomplish this goal, and produce a pathname that can be invoked as a command or referenced as a file. - use Config; - my $secure_perl_path = $Config{perlpath}; - if ($^O ne 'VMS') { - $secure_perl_path .= $Config{_exe} - unless $secure_perl_path =~ m/$Config{_exe}$/i; - } + use Config; + my $secure_perl_path = $Config{perlpath}; + if ($^O ne 'VMS') { + $secure_perl_path .= $Config{_exe} + unless $secure_perl_path =~ m/$Config{_exe}$/i; + } =back @@ -727,9 +818,9 @@ Most of the special variables related to regular expressions are side effects. Perl sets these variables when it has a successful match, so you should check the match result before using them. For instance: - if( /P(A)TT(ER)N/ ) { - print "I found $1 and $2\n"; - } + if( /P(A)TT(ER)N/ ) { + print "I found $1 and $2\n"; + } These variables are read-only and dynamically-scoped, unless we note otherwise. @@ -738,23 +829,23 @@ The dynamic nature of the regular expression variables means that their value is limited to the block that they are in, as demonstrated by this bit of code: - my $outer = 'Wallace and Grommit'; - my $inner = 'Mutt and Jeff'; + my $outer = 'Wallace and Grommit'; + my $inner = 'Mutt and Jeff'; - my $pattern = qr/(\S+) and (\S+)/; + my $pattern = qr/(\S+) and (\S+)/; - sub show_n { print "\$1 is $1; \$2 is $2\n" } + sub show_n { print "\$1 is $1; \$2 is $2\n" } - { - OUTER: - show_n() if $outer =~ m/$pattern/; + { + OUTER: + show_n() if $outer =~ m/$pattern/; - INNER: { - show_n() if $inner =~ m/$pattern/; - } + INNER: { + show_n() if $inner =~ m/$pattern/; + } - show_n(); - } + show_n(); + } The output shows that while in the C block, the values of C<$1> and C<$2> are from the match against C<$outer>. Inside the C @@ -764,40 +855,96 @@ scope). After the C block completes, the values of C<$1> and C<$2> return to the values for the match against C<$outer> even though we have not made another match: - $1 is Wallace; $2 is Grommit - $1 is Mutt; $2 is Jeff - $1 is Wallace; $2 is Grommit + $1 is Wallace; $2 is Grommit + $1 is Mutt; $2 is Jeff + $1 is Wallace; $2 is Grommit + +=head3 Performance issues + +Traditionally in Perl, any use of any of the three variables C<$`>, C<$&> +or C<$'> (or their C equivalents) anywhere in the code, caused +all subsequent successful pattern matches to make a copy of the matched +string, in case the code might subsequently access one of those variables. +This imposed a considerable performance penalty across the whole program, +so generally the use of these variables has been discouraged. + +In Perl 5.6.0 the C<@-> and C<@+> dynamic arrays were introduced that +supply the indices of successful matches. So you could for example do +this: + + $str =~ /pattern/; + + print $`, $&, $'; # bad: perfomance hit -Due to an unfortunate accident of Perl's implementation, C imposes a considerable performance penalty on all regular -expression matches in a program because it uses the C<$`>, C<$&>, and -C<$'>, regardless of whether they occur in the scope of C. For that reason, saying C in libraries is -strongly discouraged unless you import it without the match variables: + print # good: no perfomance hit + substr($str, 0, $-[0]), + substr($str, $-[0], $+[0]-$-[0]), + substr($str, $+[0]); - use English '-no_match_vars' +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

. -The C and C -modules can help you find uses of these -problematic match variables in your code. +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 -Since Perl 5.10, you can use the C

match operator flag and the -C<${^PREMATCH}>, C<${^MATCH}>, and C<${^POSTMATCH}> variables instead -so you only suffer the performance penalties. + $`; $&; "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 =item $> ($1, $2, ...) -X<$1> X<$2> X<$3> +X<$1> X<$2> X<$3> X<$I> Contains the subpattern from the corresponding set of capturing parentheses from the last successful pattern match, not counting patterns matched in nested blocks that have been exited already. +Note there is a distinction between a capture buffer which matches +the empty string a capture buffer which is optional. Eg, C<(x?)> and +C<(x)?> The latter may be undef, the former not. + These variables are read-only and dynamically-scoped. Mnemonic: like \digits. +=item @{^CAPTURE} +X<@{^CAPTURE}> X<@^CAPTURE> + +An array which exposes the contents of the capture buffers, if any, of +the last successful pattern match, not counting patterns matched +in nested blocks that have been exited already. + +Note that the 0 index of @{^CAPTURE} is equivalent to $1, the 1 index +is equivalent to $2, etc. + + if ("foal"=~/(.)(.)(.)(.)/) { + print join "-", @{^CAPTURE}; + } + +should output "f-o-a-l". + +See also L>, L and L. + +Note that unlike most other regex magic variables there is no single +letter equivalent to C<@{^CAPTURE}>. + +This variable was added in 5.25.7 + =item $MATCH =item $& @@ -807,11 +954,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 C

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. @@ -821,11 +965,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. @@ -838,12 +987,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 C

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. @@ -853,11 +998,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. @@ -870,16 +1020,12 @@ 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: - 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 C

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. @@ -889,11 +1035,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. @@ -906,7 +1057,7 @@ 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: - /Version: (.*)|Revision: (.*)/ && ($rev = $+); + /Version: (.*)|Revision: (.*)/ && ($rev = $+); This variable is read-only and dynamically-scoped. @@ -925,12 +1076,12 @@ This is primarily used inside C<(?{...})> blocks for examining text 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. @@ -950,12 +1101,14 @@ 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 %{^CAPTURE} =item %LAST_PAREN_MATCH =item %+ -X<%+> X<%LAST_PAREN_MATCH> +X<%+> X<%LAST_PAREN_MATCH> X<%{^CAPTURE}> Similar to C<@+>, the C<%+> hash allows access to the named capture buffers, should they exist, in the last successful match in the @@ -963,11 +1116,14 @@ 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). +If multiple distinct capture groups have the same name, then +C<$+{NAME}> will refer to the leftmost defined group in the match. + The underlying behaviour of C<%+> is provided by the L module. @@ -977,7 +1133,8 @@ 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. The C<%{^CAPTURE}> alias was +added in 5.25.7. This variable is read-only and dynamically-scoped. @@ -1023,12 +1180,13 @@ After a match against some variable C<$var>: =back -This variable was added in Perl 5.6. +This variable was added in Perl v5.6.0. -=item %LAST_MATCH_START +=item %{^CAPTURE_ALL} +X<%{^CAPTURE_ALL}> =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 @@ -1044,7 +1202,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"; } } @@ -1052,10 +1212,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. @@ -1069,7 +1229,8 @@ 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. The C<%{^CAPTURE_ALL}> alias was +added in 5.25.7. This variable is read-only and dynamically-scoped. @@ -1089,7 +1250,7 @@ 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. -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}> @@ -1103,7 +1264,7 @@ 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 @@ -1115,15 +1276,15 @@ although this is less efficient than using the regular built-in 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 methods each take an optional EXPR, which, if supplied, specifies the @@ -1145,17 +1306,17 @@ 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 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 @@ -1167,26 +1328,26 @@ 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 @@ -1201,7 +1362,7 @@ 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 @@ -1242,7 +1403,7 @@ 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 @@ -1254,6 +1415,9 @@ 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. +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. =item HANDLE->input_line_number( EXPR ) @@ -1291,7 +1455,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 @@ -1322,31 +1486,37 @@ 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. +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. + +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. + +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. -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. +You cannot call C on a handle, only as a +static method. See L. -See also L. Also 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 @@ -1358,6 +1528,9 @@ 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. +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. @@ -1382,6 +1555,17 @@ 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 @@ -1404,7 +1588,7 @@ 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 @@ -1413,6 +1597,9 @@ X<$^L> X<$FORMAT_FORMFEED> 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) =item $FORMAT_PAGE_NUMBER @@ -1436,7 +1623,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 @@ -1447,6 +1634,9 @@ 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 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) @@ -1507,11 +1697,11 @@ 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 @@ -1528,12 +1718,12 @@ 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 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 +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, +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 C is always set on failure and cleared on success. @@ -1555,7 +1745,7 @@ 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 @@ -1563,7 +1753,7 @@ This variable was added in Perl 5.8.9. 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 +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<$!>. @@ -1581,7 +1771,7 @@ 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. @@ -1596,14 +1786,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 @@ -1622,9 +1816,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 @@ -1675,10 +1871,12 @@ 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 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. @@ -1720,17 +1918,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. + +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. -Mnemonic: Where was the syntax error "at"? +Mnemonic: Where was the error "at"? =back @@ -1751,7 +1950,7 @@ when being compiled, such as for example to C at compile 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 @@ -1759,20 +1958,42 @@ This variable was added in Perl 5.6. 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">. +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 to the C object that is used to convert -the source code to Unicode. Thanks to this variable your Perl script -does not have to be written in UTF-8. Default is I. The direct -manipulation of this variable is highly discouraged. +This variable is no longer supported. + +It used to hold the I to the C object that was +used to convert the source code to Unicode. + +Its purpose was to allow your non-ASCII Perl +scripts not to have to be written in UTF-8; this was +useful before editors that worked on UTF-8 encoded text were common, but +that was long ago. It caused problems, such as affecting the operation +of other modules that weren't expecting it, causing general mayhem. -This variable was added in Perl 5.8.2. +If you need something like this functionality, it is recommended that use +you a simple source filter, such as L. + +If you are coming here because code of yours is being adversely affected +by someone's use of this variable, you can usually work around it by +doing this: + + local ${^ENCODING}; + +near the beginning of the functions that are getting broken. This +undefines the variable during the scope of execution of the including +function. + +This variable was added in Perl 5.8.2 and removed in 5.26.0. +Setting it to anything other than C was made fatal in Perl 5.28.0. =item ${^GLOBAL_PHASE} X<${^GLOBAL_PHASE}> @@ -1904,12 +2125,12 @@ for instance, the C pragma. The contents should be an integer; different bits of it are used for different pragmatic flags. Here's an example: - sub add_100 { $^H |= 0x100 } + sub add_100 { $^H |= 0x100 } - sub foo { - BEGIN { add_100() } - bar->baz($boon); - } + sub foo { + BEGIN { add_100() } + bar->baz($boon); + } Consider what happens during execution of the BEGIN block. At this point the BEGIN block has already been compiled, but the body of C is still @@ -1919,12 +2140,14 @@ the body of C is being compiled. Substitution of C block with: - BEGIN { require strict; strict->import('vars') } + BEGIN { require strict; strict->import('vars') } demonstrates how C is implemented. Here's a conditional version of the same lexical pragma: - BEGIN { require strict; strict->import('vars') if $condition } + BEGIN { + require strict; strict->import('vars') if $condition + } This variable was added in Perl 5.003. @@ -1933,7 +2156,9 @@ X<%^H> The C<%^H> hash provides the same scoping semantic as C<$^H>. This makes it useful for implementation of lexically scoped pragmas. See -L. +L. All the entries are stringified when accessed at +runtime, so only simple values can be accommodated. This means no +pointers to objects, for example. When putting items into C<%^H>, in order to avoid conflicting with other users of the hash there is a convention regarding which keys to use. @@ -1941,7 +2166,7 @@ A module should use only keys that begin with the module's name (the name of its main package) and a "/" character. For example, a module C should use keys such as C. -This variable was added in Perl 5.6. +This variable was added in Perl v5.6.0. =item ${^OPEN} X<${^OPEN}> @@ -1950,7 +2175,7 @@ An internal variable used by PerlIO. A string in two parts, separated by a C<\0> byte, the first part describes the input layers, the second part describes the output layers. -This variable was added in Perl 5.8.0. +This variable was added in Perl v5.8.0. =item $PERLDB @@ -2009,6 +2234,14 @@ were compiled. Save source code lines into C<@{"_<$filename"}>. +=item 0x800 + +When saving source, include evals that generate no subroutines. + +=item 0x1000 + +When saving source, include source that did not compile. + =back Some bits may be relevant at compile-time only, some at @@ -2024,7 +2257,7 @@ B<-t> or B<-TU>). This variable is read-only. -This variable was added in Perl 5.8. +This variable was added in Perl v5.8.0. =item ${^UNICODE} X<${^UNICODE}> @@ -2035,7 +2268,7 @@ the possible values. This variable is set during Perl startup and is thereafter read-only. -This variable was added in Perl 5.8.2. +This variable was added in Perl v5.8.2. =item ${^UTF8CACHE} X<${^UTF8CACHE}> @@ -2044,7 +2277,9 @@ This variable controls the state of the internal UTF-8 offset caching code. 1 for on (the default), 0 for off, -1 to debug the caching code by checking all its results against linear scans, and panicking on any discrepancy. -This variable was added in Perl 5.8.9. +This variable was added in Perl v5.8.9. It is subject to change or +removal without notice, but is currently used to avoid recalculating the +boundaries of multi-byte UTF-8-encoded characters. =item ${^UTF8LOCALE} X<${^UTF8LOCALE}> @@ -2054,7 +2289,7 @@ startup. This information is used by perl when it's in adjust-utf8ness-to-locale mode (as when run with the C<-CL> command-line switch); see L for more info on this. -This variable was added in Perl 5.8.8. +This variable was added in Perl v5.8.8. =back @@ -2072,13 +2307,11 @@ See L for details about error messages. =over 8 -=item $OFMT - =item $# -X<$#> X<$OFMT> +X<$#> C<$#> was a variable that could be used to format printed numbers. -After a deprecation cycle, its magic was removed in Perl 5.10 and +After a deprecation cycle, its magic was removed in Perl v5.10.0 and using it now triggers a warning: C<$# is no longer supported>. This is not the sigil you use in front of an array name to get the @@ -2087,24 +2320,22 @@ of an array in Perl. The two have nothing to do with each other. Deprecated in Perl 5. -Removed in Perl 5.10. +Removed in Perl v5.10.0. =item $* X<$*> C<$*> was a variable that you could use to enable multiline matching. -After a deprecation cycle, its magic was removed in Perl 5.10. +After a deprecation cycle, its magic was removed in Perl v5.10.0. Using it now triggers a warning: C<$* is no longer supported>. You should use the C and C regexp modifiers instead. Deprecated in Perl 5. -Removed in Perl 5.10. - -=item $ARRAY_BASE +Removed in Perl v5.10.0. =item $[ -X<$[> X<$ARRAY_BASE> +X<$[> This variable stores the index of the first element in an array, and of the first character in a substring. The default is 0, but you could @@ -2116,12 +2347,12 @@ directive, and cannot influence the behavior of any other file. (That's why you can only assign compile-time constants to it.) Its use is highly discouraged. -Prior to Perl 5.10, assignment to C<$[> could be seen from outer lexical +Prior to Perl v5.10.0, assignment to C<$[> could be seen from outer lexical scopes in the same file, unlike other compile-time directives (such as L). Using local() on it would bind its value strictly to a lexical block. Now it is always lexically scoped. -As of Perl 5.16, it is implemented by the L module. See +As of Perl v5.16.0, it is implemented by the L module. See L for more details on its behaviour. Under C, or C, C<$[> no longer has any @@ -2130,31 +2361,7 @@ other value will produce an error. Mnemonic: [ begins subscripts. -Deprecated in Perl 5.12. - -=item $OLD_PERL_VERSION - -=item $] -X<$]> X<$OLD_PERL_VERSION> - -See L for a more modern representation of the Perl version that allows -accurate string comparisons. - -The version + patchlevel / 1000 of the Perl interpreter. This variable -can be used to determine whether the Perl interpreter executing a -script is in the right range of versions: - - warn "No checksumming!\n" if $] < 3.019; - -The floating point representation can sometimes lead to inaccurate -numeric comparisons. - -See also the documentation of C and C -for a convenient way to fail if the running Perl interpreter is too old. - -Mnemonic: Is this version of perl in the right bracket? - -Deprecated in Perl 5.6. +Deprecated in Perl v5.12.0. =back