X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/96090e4f0acf1d24051c680595b4740bd24cb69a..7476a79c8db21237e6b6bcf579243fdfc880f8b9:/pod/perlvar.pod
diff --git a/pod/perlvar.pod b/pod/perlvar.pod
index 39bab24..ea1f601 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
+punctuation or control character. 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
+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
+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
+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
+are not optional. C<${^Foo}> denotes the scalar variable whose
+name is 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
+begin with C<^_> (control-underscore or caret-underscore). No
control-character 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
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,21 @@ 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
+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';
+ 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 +83,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,7 +106,8 @@ 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,
+abs, alarm, chomp, chop, chr, chroot,
+cos, defined, eval, evalbytes, exp, glob,
hex, int, lc, lcfirst, length, log, lstat, mkdir, oct, ord, pos, print,
quotemeta, readlink, readpipe, ref, require, reverse (in scalar context only),
rmdir, sin, split (on its second argument), sqrt, stat, study, uc, ucfirst,
@@ -139,13 +140,13 @@ The implicit variable of C.
The default place to put an input record when a 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,
+side-effects. As of perl 5.10, 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.
Mnemonic: underline is understood in certain operations.
@@ -156,7 +157,7 @@ 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
+that subroutine. Inside a subroutine, C<@_> is the default array for
the array operators C, C, C, and C.
See L.
@@ -168,13 +169,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,75 +186,30 @@ Mnemonic: works in double-quoted context.
=item $$
X<$$> X<$PID> X<$PROCESS_ID>
-The process number of the Perl running this script. You should
-consider this variable read-only, although it will be altered
+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
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).
-Mnemonic: same as shells.
-
-=item $REAL_GROUP_ID
-
-=item $GID
-
-=item $(
-X<$(> X<$GID> X<$REAL_GROUP_ID>
-
-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
-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
-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<$!>
-to detect any possible errors after an attempted change.
-
-Mnemonic: parentheses are used to I things. The real gid is the
-group you I, if you're running setgid.
-
-=item $EFFECTIVE_GROUP_ID
-
-=item $EGID
-
-=item $)
-X<$)> X<$EGID> X<$EFFECTIVE_GROUP_ID>
-
-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
-returned by C, and the subsequent ones by C,
-one of which may be the same as the first number.
+LinuxThreads is now obsolete on Linux, and 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.
-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
-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" >.
-
-You can change both the effective gid and the real gid at the same
-time by using C (use only a single numeric argument).
-Changes to C<$)> require a check to C<$!> to detect any possible errors
-after an attempted change.
+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.
-C<< $< >>, C<< $> >>, C<$(> and C<$)> can be set only on
-machines that support the corresponding I routine. C<$(>
-and C<$)> can be swapped only on machines supporting C.
+To see if your system is affected by this discrepancy check if
+C returns a false
+value. NTPL threads preserve the POSIX semantics.
-Mnemonic: parentheses are used to I things. The effective gid
-is the group that's I for you, if you're running setgid.
+Mnemonic: same as shells.
=item $PROGRAM_NAME
@@ -263,14 +219,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
@@ -280,14 +236,14 @@ 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.
@@ -296,44 +252,71 @@ C<$0> will contain the string C<"-e">.
On Linux as of perl 5.14 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.
-=item $SUBSCRIPT_SEPARATOR
+=item $REAL_GROUP_ID
-=item $SUBSEP
+=item $GID
-=item $;
-X<$;> X<$SUBSEP> X
+=item $(
+X<$(> X<$GID> X<$REAL_GROUP_ID>
-The subscript separator for multidimensional array emulation. If you
-refer to a hash element as
+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
+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
+that this is different to the effective gid (C<$)>) which does take a
+list.
- $foo{$a,$b,$c}
+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<$!>
+to detect any possible errors after an attempted change.
-it really means
+Mnemonic: parentheses are used to I things. The real gid is the
+group you I, if you're running setgid.
- $foo{join($;, $a, $b, $c)}
+=item $EFFECTIVE_GROUP_ID
-But don't put
+=item $EGID
- @foo{$a,$b,$c} # a slice--note the @
+=item $)
+X<$)> X<$EGID> X<$EFFECTIVE_GROUP_ID>
-which means
+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
+returned by C, and the subsequent ones by C,
+one of which may be the same as the first number.
- ($foo{$a},$foo{$b},$foo{$c})
+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
+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" >.
-Default is "\034", the same as SUBSEP in B. If your keys contain
-binary data there might not be any safe value for C<$;>.
+You can change both the effective gid and the real gid at the same
+time by using C (use only a single numeric argument).
+Changes to C<$)> require a check to C<$!> to detect any possible errors
+after an attempted change.
-Consider using "real" multidimensional arrays as described
-in L.
+C<< $< >>, C<< $> >>, C<$(> and C<$)> can be set only on
+machines that support the corresponding I routine. C<$(>
+and C<$)> can be swapped only on machines supporting C.
-Mnemonic: comma (the syntactic subscript separator) is a semi-semicolon.
+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
@@ -342,8 +325,8 @@ Mnemonic: comma (the syntactic subscript separator) is a semi-semicolon.
=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.
@@ -356,13 +339,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
@@ -370,55 +353,53 @@ supporting C.
Mnemonic: it's the uid you went I, if you're running setuid.
-=item $a
+=item $SUBSCRIPT_SEPARATOR
-=item $b
-X<$a> X<$b>
+=item $SUBSEP
-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 flag and the C<${^MATCH}>
+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.
This variable is read-only and dynamically-scoped.
@@ -1129,9 +843,9 @@ 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
+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.
@@ -1158,16 +872,16 @@ 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
+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.
@@ -1194,9 +908,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.
@@ -1212,10 +926,10 @@ 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.
@@ -1230,14 +944,14 @@ 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.
@@ -1253,7 +967,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).
@@ -1262,7 +976,7 @@ 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.
@@ -1281,17 +995,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.
@@ -1321,7 +1035,7 @@ This variable was added in Perl 5.6.
X<%-> X<%LAST_MATCH_START>
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
@@ -1334,7 +1048,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";
}
}
@@ -1342,10 +1058,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.
@@ -1354,7 +1070,7 @@ 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.
@@ -1369,15 +1085,15 @@ 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.
@@ -1385,9 +1101,10 @@ This variable was added in Perl 5.10.
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.
@@ -1401,50 +1118,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
@@ -1452,30 +1169,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
@@ -1486,11 +1203,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
@@ -1507,18 +1224,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 C<$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>.
@@ -1527,8 +1244,8 @@ 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 )
@@ -1540,8 +1257,8 @@ 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.
Mnemonic: what is printed when there is a "," in your print statement.
@@ -1557,20 +1274,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).
@@ -1589,15 +1306,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.
@@ -1605,33 +1322,40 @@ 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. 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 bytes from FILE. 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
+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.
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
+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.
-See also L. Also see C<$.>.
+If you perform a record read on a FILE with an encoding layer such as
+C<:encoding(latin1)> or C<:utf8>, you may get an invalid string as a
+result, may leave the FILE positioned between characters in the stream
+and may not be reading the number of bytes from the underlying file
+that you specified. This behaviour may change without warning in a
+future version of perl.
+
+See also L. Also see L$.>.
Mnemonic: / delimits line boundaries when quoting poetry.
@@ -1644,8 +1368,8 @@ 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.
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.
@@ -1658,16 +1382,16 @@ 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.
@@ -1676,7 +1400,7 @@ Mnemonic: when you want your pipes to be piping hot.
=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
@@ -1688,9 +1412,9 @@ 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)
@@ -1700,7 +1424,7 @@ L and L.
=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>.
=item HANDLE->format_page_number(EXPR)
@@ -1733,7 +1457,7 @@ 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.
Mnemonic: a "colon" in poetry is a part of a line.
@@ -1746,7 +1470,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.
@@ -1758,9 +1482,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.
@@ -1772,8 +1496,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<$^>.
@@ -1785,46 +1509,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
+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 C for details. In contrast to
+core dump information. See L for details. In contrast to
C<$!> and C<$^E>, which are set only if 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<$!>,
@@ -1837,7 +1561,7 @@ 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.
@@ -1851,14 +1575,14 @@ This variable was added in Perl 5.8.9.
=item $^E
X<$^E> X<$EXTENDED_OS_ERROR>
-Error information specific to the current operating system. At the
+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
+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
@@ -1866,8 +1590,8 @@ 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
@@ -1911,9 +1635,11 @@ Mnemonic: related to the B<-w> switch.
X<${^WARNING_BITS}>
The current set of warning checks enabled by the C