=back
-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<my>. Moreover,
-declaring C<our $_> 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.
+C<$_> is a global variable.
+
+However, between perl v5.10.0 and v5.24.0, it could be used lexically by
+writing C<my $_>. Making C<$_> refer to the global C<$_> in the same scope
+was then possible with C<our $_>. This experimental feature was removed and is
+now a fatal error, but you may encounter it in older code.
Mnemonic: underline is understood in certain operations.
C<require>, or C<use> constructs look for their library files. It
initially consists of the arguments to any B<-I> command-line
switches, followed by the default Perl library, probably
-F</usr/local/lib/perl>, followed by ".", to represent the current
-directory. ("." will not be appended if taint checks are enabled,
-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<use lib> pragma to get
-the machine-dependent library properly loaded also:
+F</usr/local/lib/perl>.
+Prior to Perl 5.26, C<.> -which represents the current directory, was included
+in C<@INC>; it has been removed. This change in behavior is documented
+in L<C<PERL_USE_UNSAFE_INC>|perlrun/PERL_USE_UNSAFE_INC> and it is
+not recommended that C<.> be re-added to C<@INC>.
+If you need to modify C<@INC> at runtime, you should use the C<use lib> pragma
+to get the machine-dependent library properly loaded as well:
use lib '/mypath/libdir/';
use SomeMod;
$str =~ /pattern/;
- print $`, $&, $'; # bad: perfomance hit
+ print $`, $&, $'; # bad: performance hit
- print # good: no perfomance hit
+ print # good: no performance hit
substr($str, 0, $-[0]),
substr($str, $-[0], $+[0]-$-[0]),
substr($str, $+[0]);
=item @{^CAPTURE}
X<@{^CAPTURE}> X<@^CAPTURE>
-An array which contains the capture buffers, if any, of the last
-successful pattern match, not counting patterns matched
+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
should output "f-o-a-l".
-See also L</$I<digits>>, L</%{^CAPTURE}> and L</%{^CAPTURE_ALL}>.
+See also L<<< /$<I<digits>> ($1, $2, ...) >>>, L</%{^CAPTURE}> and
+L</%{^CAPTURE_ALL}>.
+
+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 $+
X<$+> X<$LAST_PAREN_MATCH>
-The text matched by the last bracket of the last successful search pattern.
+The text matched by the highest used capture group of the last
+successful search pattern. It is logically equivalent to the highest
+numbered capture variable (C<$1>, C<$2>, ...) which has a defined value.
+
This is useful if you don't know which one of a set of alternative patterns
matched. For example:
The text matched by the used group most-recently closed (i.e. the group
with the rightmost closing parenthesis) of the last successful search
-pattern.
+pattern. This is subtly different from C<$+>. For example in
+
+ "ab" =~ /^((.)(.))$/
+
+we have
+
+ $1,$^N have the value "ab"
+ $2 has the value "a"
+ $3,$+ have the value "b"
This is primarily used inside C<(?{...})> blocks for examining text
recently matched. For example, to effectively capture text to a variable
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<Tie::Hash::NamedCapture> module.
X<@-> X<@LAST_MATCH_START>
C<$-[0]> is the offset of the start of the last successful match.
-C<$-[>I<n>C<]> is the offset of the start of the substring matched by
+C<$-[I<n>]> is the offset of the start of the substring matched by
I<n>-th subpattern, or undef if the subpattern did not match.
Thus, after a match against C<$_>, C<$&> coincides with C<substr $_, $-[0],
This variable was added in Perl 5.005.
+=item ${^RE_COMPILE_RECURSION_LIMIT}
+X<${^RE_COMPILE_RECURSION_LIMIT}>
+
+The current value giving the maximum number of open but unclosed
+parenthetical groups there may be at any point during a regular
+expression compilation. The default is currently 1000 nested groups.
+You may adjust it depending on your needs and the amount of memory
+available.
+
+This variable was added in Perl v5.30.0.
+
=item ${^RE_DEBUG_FLAGS}
X<${^RE_DEBUG_FLAGS}>
Remember: the value of C<$/> is a string, not a regex. B<awk> has to
be better for something. :-)
+Setting C<$/> to an empty string -- the so-called I<paragraph mode> -- merits
+special attention. When C<$/> is set to C<""> and the entire file is read in
+with that setting, any sequence of consecutive newlines C<"\n\n"> at the
+beginning of the file is discarded. With the exception of the final record in
+the file, each sequence of characters ending in two or more newlines is
+treated as one record and is read in to end in exactly two newlines. If the
+last record in the file ends in zero or one consecutive newlines, that record
+is read in with that number of newlines. If the last record ends in two or
+more consecutive newlines, it is read in with two newlines like all preceding
+records.
+
+Suppose we wrote the following string to a file:
+
+ my $string = "\n\n\n";
+ $string .= "alpha beta\ngamma delta\n\n\n";
+ $string .= "epsilon zeta eta\n\n";
+ $string .= "theta\n";
+
+ my $file = 'simple_file.txt';
+ open my $OUT, '>', $file or die;
+ print $OUT $string;
+ close $OUT or die;
+
+Now we read that file in paragraph mode:
+
+ local $/ = ""; # paragraph mode
+ open my $IN, '<', $file or die;
+ my @records = <$IN>;
+ close $IN or die;
+
+C<@records> will consist of these 3 strings:
+
+ (
+ "alpha beta\ngamma delta\n\n",
+ "epsilon zeta eta\n\n",
+ "theta\n",
+ )
+
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
function.
This variable was added in Perl 5.8.2 and removed in 5.26.0.
+Setting it to anything other than C<undef> was made fatal in Perl 5.28.0.
=item ${^GLOBAL_PHASE}
X<${^GLOBAL_PHASE}>
This variable was added in Perl v5.8.0.
+=item ${^SAFE_LOCALES}
+X<${^SAFE_LOCALES}>
+
+Reflects if safe locale operations are available to this perl (when the
+value is 1) or not (the value is 0). This variable is always 1 if the
+perl has been compiled without threads. It is also 1 if this perl is
+using thread-safe locale operations. Note that an individual thread may
+choose to use the global locale (generally unsafe) by calling
+L<perlapi/switch_to_global_locale>. This variable currently is still
+set to 1 in such threads.
+
+This variable is read-only.
+
+This variable was added in Perl v5.28.0.
+
=item ${^UNICODE}
X<${^UNICODE}>
L<strict>). Using local() on it would bind its value strictly to a lexical
block. Now it is always lexically scoped.
-As of Perl v5.16.0, it is implemented by the L<arybase> module. See
-L<arybase> for more details on its behaviour.
+As of Perl v5.16.0, it is implemented by the L<arybase> module.
-Under C<use v5.16>, or C<no feature "array_base">, C<$[> no longer has any
-effect, and always contains 0. Assigning 0 to it is permitted, but any
-other value will produce an error.
+As of Perl v5.30.0, or under C<use v5.16>, or C<no feature "array_base">,
+C<$[> no longer has any effect, and always contains 0.
+Assigning 0 to it is permitted, but any other value will produce an error.
Mnemonic: [ begins subscripts.