scope. In Perl v5.14 and earlier, C<continue> required the C<"switch">
feature, like the other keywords.
-C<evalbytes> is only available with with the C<"evalbytes"> feature (see
+C<evalbytes> is only available with the C<"evalbytes"> feature (see
L<feature>) or if prefixed with C<CORE::>. C<__SUB__> is only available
-with with the C<"current_sub"> feature or if prefixed with C<CORE::>. Both
+with the C<"current_sub"> feature or if prefixed with C<CORE::>. Both
the C<"evalbytes"> and C<"current_sub"> features are enabled automatically
with a C<use v5.16> (or higher) declaration in the current scope.
print "Text\n" if -T _;
print "Binary\n" if -B _;
-As of Perl 5.9.1, as a form of purely syntactic sugar, you can stack file
+As of Perl 5.10.0, as a form of purely syntactic sugar, you can stack file
test operators, in a way that C<-f -w -x $file> is equivalent to
C<-x $file && -w _ && -f _>. (This is only fancy fancy: if you use
the return value of C<-f $file> as an argument to another filetest
is used. Because a C<bless> is often the last thing in a constructor,
it returns the reference for convenience. Always use the two-argument
version if a derived class might inherit the function doing the blessing.
-SeeL<perlobj> for more about the blessing (and blessings) of objects.
+See L<perlobj> for more about the blessing (and blessings) of objects.
Consider always blessing objects in CLASSNAMEs that are mixed case.
Namespaces with all lowercase names are considered reserved for
subroutine happens to have been deleted from the symbol table.
C<$hasargs> is true if a new instance of C<@_> was set up for the frame.
C<$hints> and C<$bitmask> contain pragmatic hints that the caller was
-compiled with. The C<$hints> and C<$bitmask> values are subject to change
-between versions of Perl, and are not meant for external use.
+compiled with. C<$hints> corresponds to C<$^H>, and C<$bitmask>
+corresponds to C<${^WARNING_BITS}>. The
+C<$hints> and C<$bitmask> values are subject
+to change between versions of Perl, and are not meant for external use.
C<$hinthash> is a reference to a hash containing the value of C<%^H> when the
caller was compiled, or C<undef> if C<%^H> was empty. Do not modify the values
=item do SUBROUTINE(LIST)
X<do>
-This form of subroutine call is deprecated. SUBROUTINE can be a bareword,
-a scalar variable or a subroutine beginning with C<&>.
+This form of subroutine call is deprecated. SUBROUTINE can be a bareword
+or scalar variable.
=item do EXPR
X<do>
=item dump LABEL
X<dump> X<core> X<undump>
+=item dump EXPR
+
=item dump
=for Pod::Functions create an immediate core dump
program. When the new binary is executed it will begin by executing
a C<goto LABEL> (with all the restrictions that C<goto> suffers).
Think of it as a goto with an intervening core dump and reincarnation.
-If C<LABEL> is omitted, restarts the program from the top.
+If C<LABEL> is omitted, restarts the program from the top. The
+C<dump EXPR> form, available starting in Perl 5.18.0, allows a name to be
+computed at run time, being otherwise identical to C<dump LABEL>.
B<WARNING>: Any files opened at the time of the dump will I<not>
be open any more when the program is reincarnated, with possible
it as C<CORE::dump()>, if you don't want to be warned against a possible
typo.
+Unlike most named operators, this has the same precedence as assignment.
+It is also exempt from the looks-like-a-function rule, so
+C<dump ("foo")."bar"> will cause "bar" to be part of the argument to
+C<dump>.
+
Portability issues: L<perlport/dump>.
=item each HASH
while (($key,$value) = each $hashref) { ... }
+As of Perl 5.18 you can use a bare C<each> in a C<while> loop,
+which will set C<$_> on every iteration.
+
+ while(each %ENV) {
+ print "$_=$ENV{$_}\n";
+ }
+
To avoid confusing would-be users of your code who are running earlier
versions of Perl with mysterious syntax errors, put this sort of thing at
the top of your file to signal that your code will work I<only> on Perls of
use 5.012; # so keys/values/each work on arrays
use 5.014; # so keys/values/each work on scalars (experimental)
+ use 5.018; # so each assigns to $_ in a lone while test
See also C<keys>, C<values>, and C<sort>.
it tried to run a program named I<"echo surprise">, didn't find it, and set
C<$?> to a non-zero value indicating failure.
-Beginning with v5.6.0, Perl attempts to flush all files opened for
-output before the exec, but this may not be supported on some platforms
-(see L<perlport>). To be safe, you may need to set C<$|> ($AUTOFLUSH
-in English) or call the C<autoflush()> method of C<IO::Handle> on any
-open handles to avoid lost output.
+Perl attempts to flush all files opened for output before the exec,
+but this may not be supported on some platforms (see L<perlport>).
+To be safe, you may need to set C<$|> ($AUTOFLUSH in English) or
+call the C<autoflush()> method of C<IO::Handle> on any open handles
+to avoid lost output.
Note that C<exec> will not call your C<END> blocks, nor will it invoke
C<DESTROY> methods on your objects.
example, using copy-on-write technology on data pages), making it the
dominant paradigm for multitasking over the last few decades.
-Beginning with v5.6.0, Perl attempts to flush all files opened for
+Perl attempts to flush all files opened for
output before forking the child process, but this may not be supported
on some platforms (see L<perlport>). To be safe, you may need to set
C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method of
@many = glob "{apple,tomato,cherry}={green,yellow,red}";
-Beginning with v5.6.0, this operator is implemented using the standard
+This operator is implemented using the standard
C<File::Glob> extension. See L<File::Glob> for details, including
C<bsd_glob> which does not treat whitespace as a pattern separator.
As shown in this example, C<goto-EXPR> is exempt from the "looks like a
function" rule. A pair of parentheses following it does not (necessarily)
delimit its argument. C<goto("NE")."XT"> is equivalent to C<goto NEXT>.
+Also, unlike most named operators, this has the same precedence as
+assignment.
Use of C<goto-LABEL> or C<goto-EXPR> to jump into a construct is
deprecated and will issue a warning. Even then, it may not be used to
Unlike in the shell, if SIGNAL is negative, it kills process groups instead
of processes. That means you usually
want to use positive not negative signals.
-You may also use a signal name in quotes.
+
+You may also use a signal name in quotes. A negative signal name is the
+same as a negative signal number, killing process groups instead of processes.
+For example, C<kill -KILL, $pgrp> will send C<SIGKILL> to the entire process
+group specified.
The behavior of kill when a I<PROCESS> number is zero or negative depends on
the operating system. For example, on POSIX-conforming systems, zero will
-signal the current process group and -1 will signal all processes.
+signal the current process group, -1 will signal all processes, and any
+other negative PROCESS number will act as a negative signal number and
+kill the entire process group specified.
+
+If both the SIGNAL and the PROCESS are negative, the results are undefined.
+A warning may be produced in a future version.
See L<perlipc/"Signals"> for more details.
=item last LABEL
X<last> X<break>
+=item last EXPR
+
=item last
=for Pod::Functions exit a block prematurely
The C<last> command is like the C<break> statement in C (as used in
loops); it immediately exits the loop in question. If the LABEL is
-omitted, the command refers to the innermost enclosing loop. The
+omitted, the command refers to the innermost enclosing
+loop. The C<last EXPR> form, available starting in Perl
+5.18.0, allows a label name to be computed at run time,
+and is otherwise identical to C<last LABEL>. The
C<continue> block, if any, is not executed:
LINE: while (<STDIN>) {
See also L</continue> for an illustration of how C<last>, C<next>, and
C<redo> work.
+Unlike most named operators, this has the same precedence as assignment.
+It is also exempt from the looks-like-a-function rule, so
+C<last ("foo")."bar"> will cause "bar" to be part of the argument to
+C<last>.
+
=item lc EXPR
X<lc> X<lowercase>
=item next LABEL
X<next> X<continue>
+=item next EXPR
+
=item next
=for Pod::Functions iterate a block prematurely
Note that if there were a C<continue> block on the above, it would get
executed even on discarded lines. If LABEL is omitted, the command
-refers to the innermost enclosing loop.
+refers to the innermost enclosing loop. The C<next EXPR> form, available
+as of Perl 5.18.0, allows a label name to be computed at run time, being
+otherwise identical to C<next LABEL>.
C<next> cannot be used to exit a block which returns a value such as
C<eval {}>, C<sub {}>, or C<do {}>, and should not be used to exit
See also L</continue> for an illustration of how C<last>, C<next>, and
C<redo> work.
+Unlike most named operators, this has the same precedence as assignment.
+It is also exempt from the looks-like-a-function rule, so
+C<next ("foo")."bar"> will cause "bar" to be part of the argument to
+C<next>.
+
=item no MODULE VERSION LIST
X<no declarations>
X<unimporting>
to the temporary file first. You will need to seek() to do the
reading.
-Since v5.8.0, Perl has built using PerlIO by default. Unless you've
+Perl is built using PerlIO by default; Unless you've
changed this (such as building Perl with C<Configure -Uuseperlio>), you can
open filehandles directly to Perl scalars via:
See L<perlipc/"Safe Pipe Opens"> for more examples of this.
-Beginning with v5.6.0, Perl will attempt to flush all files opened for
+Perl will attempt to flush all files opened for
output before any operation that may do a fork, but this may not be
supported on some platforms (see L<perlport>). To be safe, you may need
to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
}
B<WARNING:> The previous example has a bug because the automatic
-close that happens when the refcount on C<handle> does not
+close that happens when the refcount on C<handle> reaches zero does not
properly detect and report failures. I<Always> close the handle
yourself and inspect the return value.
=for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping)
-C<our> associates a simple name with a package variable in the current
-package for use within the current scope. When C<use strict 'vars'> is in
-effect, C<our> lets you use declared global variables without qualifying
-them with package names, within the lexical scope of the C<our> declaration.
-In this way C<our> differs from C<use vars>, which is package-scoped.
+C<our> makes a lexical alias to a package variable of the same name in the current
+package for use within the current lexical scope.
-Unlike C<my> or C<state>, which allocates storage for a variable and
-associates a simple name with that storage for use within the current
-scope, C<our> associates a simple name with a package (read: global)
-variable in the current package, for use within the current lexical scope.
-In other words, C<our> has the same scoping rules as C<my> or C<state>, but
-does not necessarily create a variable.
+C<our> has the same scoping rules as C<my> or C<state>, but C<our> only
+declares an alias, whereas C<my> or C<state> both declare a variable name and
+allocate storage for that name within the current scope.
+
+This means that when C<use strict 'vars'> is in effect, C<our> lets you use
+a package variable without qualifying it with the package name, but only within
+the lexical scope of the C<our> declaration. In this way, C<our> differs from
+C<use vars>, which allows use of an unqualified name I<only> within the
+affected package, but across scopes.
If more than one value is listed, the list must be placed
in parentheses.
our $foo;
our($bar, $baz);
-An C<our> declaration declares a global variable that will be visible
+An C<our> declaration declares an alias for a package variable that will be visible
across its entire lexical scope, even across package boundaries. The
package in which the variable is entered is determined at the point
of the declaration, not at the point of use. This means the following
=item *
-Starting with Perl 5.9.2, integer and floating-point formats, along with
+Starting with Perl 5.10.0, integer and floating-point formats, along with
the C<p> and C<P> formats and C<()> groups, may all be followed by the
C<< > >> or C<< < >> endianness modifiers to respectively enforce big-
or little-endian byte-order. These modifiers are especially useful
like C<STDOUT>, C<ARGV>, C<ENV>, and the punctuation variables.
A package statement affects dynamic variables only, including those
-you've used C<local> on, but I<not> lexical variables, which are created
+you've used C<local> on, but I<not> lexically-scoped variables, which are created
with C<my>, C<state>, or C<our>. Typically it would be the first
declaration in a file included by C<require> or C<use>. You can switch into a
package in more than one place, since this only determines which default
the function whose prototype you want to retrieve.
If FUNCTION is a string starting with C<CORE::>, the rest is taken as a
-name for a Perl builtin. If the builtin is not I<overridable> (such as
-C<qw//>) or if its arguments cannot be adequately expressed by a prototype
+name for a Perl builtin. If the builtin's arguments
+cannot be adequately expressed by a prototype
(such as C<system>), prototype() returns C<undef>, because the builtin
does not really behave like a Perl function. Otherwise, the string
describing the equivalent prototype is returned.
@dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
closedir $dh;
-As of Perl 5.11.2 you can use a bare C<readdir> in a C<while> loop,
+As of Perl 5.12 you can use a bare C<readdir> in a C<while> loop,
which will set C<$_> on every iteration.
opendir(my $dh, $some_dir) || die;
=item redo LABEL
X<redo>
+=item redo EXPR
+
=item redo
=for Pod::Functions start this loop iteration over again
The C<redo> command restarts the loop block without evaluating the
conditional again. The C<continue> block, if any, is not executed. If
the LABEL is omitted, the command refers to the innermost enclosing
-loop. Programs that want to lie to themselves about what was just input
+loop. The C<redo EXPR> form, available starting in Perl 5.18.0, allows a
+label name to be computed at run time, and is otherwise identical to C<redo
+LABEL>. Programs that want to lie to themselves about what was just input
normally use this command:
# a simpleminded Pascal comment stripper
See also L</continue> for an illustration of how C<last>, C<next>, and
C<redo> work.
+Unlike most named operators, this has the same precedence as assignment.
+It is also exempt from the looks-like-a-function rule, so
+C<redo ("foo")."bar"> will cause "bar" to be part of the argument to
+C<redo>.
+
=item ref EXPR
X<ref> X<reference>
or do FILE automatically returns the value of the last expression
evaluated.)
+Unlike most named operators, this is also exempt from the
+looks-like-a-function rule, so C<return ("foo")."bar"> will
+cause "bar" to be part of the argument to C<return>.
+
=item reverse LIST
X<reverse> X<rev> X<invert>
into more fields than necessary. Thus, when assigning to a list,
if LIMIT is omitted (or zero), then LIMIT is treated as though it
were one larger than the number of variables in the list; for the
-following, LIMIT is implicitly 4:
+following, LIMIT is implicitly 3:
- ($login, $passwd, $remainder) = split(/:/);
+ ($login, $passwd) = split(/:/);
Note that splitting an EXPR that evaluates to the empty string always
produces zero fields, regardless of the LIMIT specified.
use 5.014; # so srand returns the seed
If C<srand()> is not called explicitly, it is called implicitly without a
-parameter at the first use of the C<rand> operator. However, this was not true
-of versions of Perl before 5.004, so if your script will run under older
-Perl versions, it should call C<srand>; otherwise most programs won't call
-C<srand()> at all.
-
-But there are a few situations in recent Perls where programs are likely to
-want to call C<srand>. One is for generating predictable results generally for
+parameter at the first use of the C<rand> operator.
+However, there are a few situations where programs are likely to
+want to call C<srand>. One is for generating predictable results, generally for
testing or debugging. There, you use C<srand($seed)>, with the same C<$seed>
each time. Another case is that you may want to call C<srand()>
after a C<fork()> to avoid child processes sharing the same seed value as the
produce the same results as C<srand(42.1)>. To be safe, always pass
C<srand> an integer.
-In versions of Perl prior to 5.004 the default seed was just the
-current C<time>. This isn't a particularly good seed, so many old
-programs supply their own seed value (often C<time ^ $$> or C<time ^
-($$ + ($$ << 15))>), but that isn't necessary any more.
-
-Frequently called programs (like CGI scripts) that simply use
-
- time ^ $$
-
-for a seed can fall prey to the mathematical property that
-
- a^b == (a+1)^(b+1)
-
-one-third of the time. So don't do that.
-
A typical use of the returned seed is for a test program which has too many
combinations to test comprehensively in the time available to it each run. It
can test a random subset each time, and should there be a failure, log the seed
it is split into words and passed directly to C<execvp>, which is
more efficient.
-Beginning with v5.6.0, Perl will attempt to flush all files opened for
+Perl will attempt to flush all files opened for
output before any operation that may do a fork, but this may not be
supported on some platforms (see L<perlport>). To be safe, you may need
to set C<$|> ($AUTOFLUSH in English) or call the C<autoflush()> method
version as defined by the C<feature> pragma, disabling any features
not in the requested version's feature bundle. See L<feature>.
Similarly, if the specified Perl version is greater than or equal to
-5.11.0, strictures are enabled lexically as
+5.12.0, strictures are enabled lexically as
with C<use strict>. Any explicit use of
C<use strict> or C<no strict> overrides C<use VERSION>, even if it comes
before it. In both cases, the F<feature.pm> and F<strict.pm> files are
$atime = $mtime = time;
utime $atime, $mtime, @ARGV;
-Since Perl 5.7.2, if the first two elements of the list are C<undef>,
+Since Perl 5.8.0, if the first two elements of the list are C<undef>,
the utime(2) syscall from your C library is called with a null second
argument. On most systems, this will set the file's access and
modification times to the current time (i.e., equivalent to the example