C<redo>, C<return>, C<sub>, C<__SUB__>, C<wantarray>
C<break> is available only if you enable the experimental C<"switch">
-feature or use the C<CORE::> prefix. The C<"switch"> feature also enables
+feature or use the C<CORE::> prefix. The C<"switch"> feature also enables
the C<default>, C<given> and C<when> statements, which are documented in
-L<perlsyn/"Switch Statements">. The C<"switch"> feature is enabled
+L<perlsyn/"Switch Statements">. The C<"switch"> feature is enabled
automatically with a C<use v5.10> (or higher) declaration in the current
-scope. In Perl v5.14 and earlier, C<continue> required the C<"switch">
+scope. In Perl v5.14 and earlier, C<continue> required the C<"switch">
feature, like the other keywords.
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 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.
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
+C<-x $file && -w _ && -f _>. (This is only fancy syntax: if you use
the return value of C<-f $file> as an argument to another filetest
operator, no special magic will happen.)
# ...
}
-If VARIABLE is a hash, it chomps the hash's values, but not its keys.
+If VARIABLE is a hash, it chomps the hash's values, but not its keys,
+resetting the C<each> iterator in the process.
You can actually chomp anything that's an lvalue, including an assignment:
Chops off the last character of a string and returns the character
chopped. It is much more efficient than C<s/.$//s> because it neither
scans nor copies the string. If VARIABLE is omitted, chops C<$_>.
-If VARIABLE is a hash, it chops the hash's values, but not its keys.
+If VARIABLE is a hash, it chops the hash's values, but not its keys,
+resetting the C<each> iterator in the process.
You can actually chop anything that's an lvalue, including an assignment.
do 'stat.pl';
-is just like
+is largely like
eval `cat stat.pl`;
-except that it's more efficient and concise, keeps track of the current
+except that it's more concise, runs no external processes, keeps track of
+the current
filename for error messages, searches the C<@INC> directories, and updates
C<%INC> if the file is found. See L<perlvar/@INC> and L<perlvar/%INC> for
these variables. It also differs in that code evaluated with C<do FILENAME>
(not the value) in a hash, or the index in an array.
Hash entries are returned in an apparently random order. The actual random
-order is subject to change in future versions of Perl, but it is
-guaranteed to be in the same order as either the C<keys> or C<values>
-function would produce on the same (unmodified) hash. Since Perl
-5.8.2 the ordering can be different even between different runs of Perl
-for security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
+order is specific to a given hash; the exact same series of operations
+on two hashes may result in a different order for each hash. Any insertion
+into the hash may change the order, as will any deletion, with the exception
+that the most recent key returned by C<each> or C<keys> may be deleted
+without changing the order. So long as a given hash is unmodified you may
+rely on C<keys>, C<values> and C<each> to repeatedly return the same order
+as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
+details on why hash order is randomized. Aside from the guarantees
+provided here the exact details of Perl's hash algorithm and the hash
+traversal order are subject to change in any release of Perl.
After C<each> has returned all entries from the hash or array, the next
call to C<each> returns the empty list in list context and C<undef> in
=for Pod::Functions catch exceptions or compile and run code
-In the first form, the return value of EXPR is parsed and executed as if it
+In the first form, often referred to as a "string eval", the return
+value of EXPR is parsed and executed as if it
were a little Perl program. The value of the expression (which is itself
determined within scalar context) is first parsed, and if there were no
errors, executed as a block within the lexical context of the current Perl
always treats its input as a byte stream and works properly with source
filters, and the L<feature> pragma.
+Problems can arise if the string expands a scalar containing a floating
+point number. That scalar can expand to letters, such as C<"NaN"> or
+C<"Infinity">; or, within the scope of a C<use locale>, the decimal
+point character may be something other than a dot (such as a comma).
+None of these are likely to parse as you are likely expecting.
+
In the second form, the code within the BLOCK is parsed only once--at the
same time the code surrounding the C<eval> itself was parsed--and executed
within the context of the current Perl program. This form is typically
C<eval BLOCK> does I<not> count as a loop, so the loop control statements
C<next>, C<last>, or C<redo> cannot be used to leave or restart the block.
-An C<eval ''> executed within the C<DB> package doesn't see the usual
+An C<eval ''> executed within a subroutine defined
+in the C<DB> package doesn't see the usual
surrounding lexical scope, but rather the scope of the first non-DB piece
of code that called it. You don't normally need to worry about this unless
you are writing a Perl debugger.
If EXPR is omitted, uses C<$_>.
-This function behaves the same way under various pragma, such as in a locale,
-as L</lc> does.
+This function behaves the same way under various pragma, such as within
+S<C<"use feature 'unicode_strings">>, as L</lc> does, with the single
+exception of C<fc> of LATIN CAPITAL LETTER SHARP S (U+1E9E) within the
+scope of S<C<use locale>>. The foldcase of this character would
+normally be C<"ss">, but as explained in the L</lc> section, case
+changes that cross the 255/256 boundary are problematic under locales,
+and are hence prohibited. Therefore, this function under locale returns
+instead the string C<"\x{17F}\x{17F}">, which is the LATIN SMALL LETTER
+LONG S. Since that character itself folds to C<"s">, the string of two
+of them together should be equivalent to a single U+1E9E when foldcased.
While the Unicode Standard defines two additional forms of casefolding,
one for Turkic languages and one that never maps one character into multiple
C<Unicode::Casing> may be used to provide an implementation.
This keyword is available only when the C<"fc"> feature is enabled,
-or when prefixed with C<CORE::>; See L<feature>. Alternately,
+or when prefixed with C<CORE::>; See L<feature>. Alternately,
include a C<use v5.16> or later to the current scope.
=item fcntl FILEHANDLE,FUNCTION,SCALAR
You can use this to find out whether two handles refer to the
same underlying descriptor:
- if (fileno(THIS) == fileno(THAT)) {
+ if (fileno(THIS) != -1 && fileno(THIS) == fileno(THAT)) {
print "THIS and THAT are dups\n";
+ } elsif (fileno(THIS) != -1 && fileno(THAT) != -1) {
+ print "THIS and THAT have different " .
+ "underlying file descriptors\n";
+ } else {
+ print "At least one of THIS and THAT does " .
+ "not have a real file descriptor\n";
}
=item flock FILEHANDLE,OPERATION
The C<POSIX::getattr> function can do this more portably on
systems purporting POSIX compliance. See also the C<Term::ReadKey>
-module from your nearest CPAN site; details on CPAN can be found under
-L<perlmodlib/CPAN>.
+module from your nearest L<CPAN|http://www.cpan.org> site.
=item getlogin
X<getlogin> X<login>
Note for Linux users: Between v5.8.1 and v5.16.0 Perl would work
around non-POSIX thread semantics the minority of Linux systems (and
Debian GNU/kFreeBSD systems) that used LinuxThreads, this emulation
-has since been removed. See the documentation for L<$$|perlvar/$$> for
+has since been removed. See the documentation for L<$$|perlvar/$$> for
details.
Portability issues: L<perlport/getppid>.
=for Pod::Functions create spaghetti code
-The C<goto-LABEL> form finds the statement labeled with LABEL and
+The C<goto LABEL> form finds the statement labeled with LABEL and
resumes execution there. It can't be used to get out of a block or
subroutine given to C<sort>. It can be used to go almost anywhere
else within the dynamic scope, including out of subroutines, but it's
does not offer named loops combined with loop control. Perl does, and
this replaces most structured uses of C<goto> in other languages.)
-The C<goto-EXPR> form expects a label name, whose scope will be resolved
+The C<goto EXPR> form expects to evaluate C<EXPR> to a code reference or
+a label name. If it evaluates to a code reference, it will be handled
+like C<goto &NAME>, below. This is especially useful for implementing
+tail recursion via C<goto __SUB__>.
+
+If the expression evaluates to a label name, its scope will be resolved
dynamically. This allows for computed C<goto>s per FORTRAN, but isn't
necessarily recommended if you're optimizing for maintainability:
goto ("FOO", "BAR", "GLARCH")[$i];
-As shown in this example, C<goto-EXPR> is exempt from the "looks like a
+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
+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
go into any construct that requires initialization, such as a
subroutine or a C<foreach> loop. It also can't be used to go into a
construct that is optimized away.
-The C<goto-&NAME> form is quite different from the other forms of
+The C<goto &NAME> form is quite different from the other forms of
C<goto>. In fact, it isn't a goto in the normal sense at all, and
doesn't have the stigma associated with other gotos. Instead, it
exits the current subroutine (losing any changes set by local()) and
This is usually something to be avoided when writing clear code.
If C<$_> is lexical in the scope where the C<grep> appears (because it has
-been declared with C<my $_>) then, in addition to being locally aliased to
+been declared with the deprecated C<my $_> construct)
+then, in addition to being locally aliased to
the list elements, C<$_> keeps being lexical inside the block; i.e., it
can't be seen from the outside, avoiding any potential side-effects.
releases prior to 5.12 will produce a syntax error if you try to use an
array argument. In scalar context, returns the number of keys or indices.
-The keys of a hash are returned in an apparently random order. The actual
-random order is subject to change in future versions of Perl, but it
-is guaranteed to be the same order as either the C<values> or C<each>
-function produces (given that the hash has not been modified). Since
-Perl 5.8.1 the ordering can be different even between different runs of
-Perl for security reasons (see L<perlsec/"Algorithmic Complexity
-Attacks">).
+Hash entries are returned in an apparently random order. The actual random
+order is specific to a given hash; the exact same series of operations
+on two hashes may result in a different order for each hash. Any insertion
+into the hash may change the order, as will any deletion, with the exception
+that the most recent key returned by C<each> or C<keys> may be deleted
+without changing the order. So long as a given hash is unmodified you may
+rely on C<keys>, C<values> and C<each> to repeatedly return the same order
+as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
+details on why hash order is randomized. Aside from the guarantees
+provided here the exact details of Perl's hash algorithm and the hash
+traversal order are subject to change in any release of Perl.
As a side effect, calling keys() resets the internal iterator of the HASH or
ARRAY (see L</each>). In particular, calling keys() in void context resets
processes successfully signaled (which is not necessarily the
same as the number actually killed).
- $cnt = kill 1, $child1, $child2;
- kill 9, @goners;
+ $cnt = kill 'HUP', $child1, $child2;
+ kill 'KILL', @goners;
+
+SIGNAL may be either a signal name (a string) or a signal number. A signal
+name may start with a C<SIG> prefix, thus C<FOO> and C<SIGFOO> refer to the
+same signal. The string form of SIGNAL is recommended for portability because
+the same signal may have different numbers in different operating systems.
-If SIGNAL is zero, no signal is sent to the process, but C<kill>
-checks whether it's I<possible> to send a signal to it (that
-means, to be brief, that the process is owned by the same user, or we are
+A list of signal names supported by the current platform can be found in
+C<$Config{sig_name}>, which is provided by the C<Config> module. See L<Config>
+for more details.
+
+A negative signal name is the same as a negative signal number, killing process
+groups instead of processes. For example, C<kill '-KILL', $pgrp> and
+C<kill -9, $pgrp> will send C<SIGKILL> to
+the entire process group specified. That
+means you usually want to use positive not negative signals.
+
+If SIGNAL is either the number 0 or the string C<ZERO> (or C<SIGZERO>),
+no signal is sent to
+the process, but C<kill> checks whether it's I<possible> to send a signal to it
+(that means, to be brief, that the process is owned by the same user, or we are
the super-user). This is useful to check that a child process is still
alive (even if only as a zombie) and hasn't changed its UID. See
L<perlport> for notes on the portability of this construct.
-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. 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, -1 will signal all processes, and any
=item If C<use bytes> is in effect:
-=over
-
-=item On EBCDIC platforms
-
-The results are what the C language system call C<tolower()> returns.
-
-=item On ASCII platforms
-
The results follow ASCII semantics. Only characters C<A-Z> change, to C<a-z>
respectively.
-=back
-
=item Otherwise, if C<use locale> (but not C<use locale ':not_characters'>) is in effect:
Respects current LC_CTYPE locale for code points < 256; and uses Unicode
Unicode semantics are used for the case change.
-=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'>) is in effect:
+=item Otherwise, if C<use feature 'unicode_strings'> or C<use locale ':not_characters'> is in effect:
Unicode semantics are used for the case change.
=item Otherwise:
-=over
-
-=item On EBCDIC platforms
-
-The results are what the C language system call C<tolower()> returns.
-
-=item On ASCII platforms
-
ASCII semantics are used for the case change. The lowercase of any character
outside the ASCII range is the character itself.
=back
-=back
-
=item lcfirst EXPR
X<lcfirst> X<lowercase>
=item length
-=for Pod::Functions return the number of bytes in a string
+=for Pod::Functions return the number of characters in a string
Returns the length in I<characters> of the value of EXPR. If EXPR is
omitted, returns the length of C<$_>. If EXPR is undefined, returns
the original list for which the BLOCK or EXPR evaluates to true.
If C<$_> is lexical in the scope where the C<map> appears (because it has
-been declared with C<my $_>), then, in addition to being locally aliased to
+been declared with the deprecated C<my $_> construct),
+then, in addition to being locally aliased to
the list elements, C<$_> keeps being lexical inside the block; that is, it
can't be seen from the outside, avoiding any potential side-effects.
Portability issues: L<perlport/msgsnd>.
-=item my EXPR
+=item my VARLIST
X<my>
-=item my TYPE EXPR
+=item my TYPE VARLIST
-=item my EXPR : ATTRS
+=item my VARLIST : ATTRS
-=item my TYPE EXPR : ATTRS
+=item my TYPE VARLIST : ATTRS
=for Pod::Functions declare and assign a local variable (lexical scoping)
A C<my> declares the listed variables to be local (lexically) to the
-enclosing block, file, or C<eval>. If more than one value is listed,
+enclosing block, file, or C<eval>. If more than one variable is listed,
the list must be placed in parentheses.
The exact semantics and interface of TYPE and ATTRS are still
L<perlsub/"Private Variables via my()"> for details, and L<fields>,
L<attributes>, and L<Attribute::Handlers>.
+Note that with a parenthesised list, C<undef> can be used as a dummy
+placeholder, for example to skip assignment of initial values:
+
+ my ( undef, $min, $hour ) = localtime;
+
=item next LABEL
X<next> X<continue>
For the reverse, see L</chr>.
See L<perlunicode> for more about Unicode.
-=item our EXPR
+=item our VARLIST
X<our> X<global>
-=item our TYPE EXPR
+=item our TYPE VARLIST
-=item our EXPR : ATTRS
+=item our VARLIST : ATTRS
-=item our TYPE EXPR : ATTRS
+=item our TYPE VARLIST : ATTRS
=for Pod::Functions +5.6.0 declare and assign a package variable (lexical scoping)
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
+If more than one variable is listed, the list must be placed
in parentheses.
our $foo;
L<perlsub/"Private Variables via my()"> for details, and L<fields>,
L<attributes>, and L<Attribute::Handlers>.
+Note that with a parenthesised list, C<undef> can be used as a dummy
+placeholder, for example to skip assignment of initial values:
+
+ our ( undef, $min, $hour ) = localtime;
+
=item pack TEMPLATE,LIST
X<pack>
=begin comment
Larry recalls that the hex and bit string formats (H, h, B, b) were added to
-pack for processing data from NASA's Magellan probe. Magellan was in an
+pack for processing data from NASA's Magellan probe. Magellan was in an
elliptical orbit, using the antenna for the radar mapping when close to
Venus and for communicating data back to Earth for the rest of the orbit.
There were two transmission units, but one of these failed, and then the
length. For example:
This code: gives this result:
-
+
unpack("W/a", "\004Gurusamy") ("Guru")
unpack("a3/A A*", "007 Bond J ") (" Bond", "J")
unpack("a3 x2 /A A*", "007: Bond, J.") ("Bond, J", ".")
considered to be word characters.
Otherwise, Perl quotes non-ASCII characters using an adaptation from
-Unicode (see L<http://www.unicode.org/reports/tr31/>.)
+Unicode (see L<http://www.unicode.org/reports/tr31/>).
The only code points that are quoted are those that have any of the
Unicode properties: Pattern_Syntax, Pattern_White_Space, White_Space,
Default_Ignorable_Code_Point, or General_Category=Control.
hasn't already been included. The file is included via the do-FILE
mechanism, which is essentially just a variety of C<eval> with the
caveat that lexical variables in the invoking script will be invisible
-to the included code. Has semantics similar to the following subroutine:
+to the included code. If it were implemented in pure Perl, it
+would have semantics similar to the following:
+
+ use Carp 'croak';
+ use version;
sub require {
my ($filename) = @_;
+ if ( my $version = eval { version->parse($filename) } ) {
+ if ( $version > $^V ) {
+ my $vn = $version->normal;
+ croak "Perl $vn required--this is only $^V, stopped";
+ }
+ return 1;
+ }
if (exists $INC{$filename}) {
return 1 if $INC{$filename};
- die "Compilation failed in require";
+ croak "Compilation failed in require";
}
my ($realfilename,$result);
ITER: {
$realfilename = "$prefix/$filename";
if (-f $realfilename) {
$INC{$filename} = $realfilename;
- $result = do $realfilename;
+ my $caller = caller;
+ my $do_as_caller = eval qq{
+ package $caller;
+ sub { do \$_[0] }
+ };
+ $result = $do_as_caller->($realfilename);
last ITER;
}
}
- die "Can't find $filename in \@INC";
+ croak "Can't locate $filename in \@INC";
}
if ($@) {
$INC{$filename} = undef;
- die $@;
+ croak $@;
} elsif (!$result) {
delete $INC{$filename};
- die "$filename did not return true value";
+ croak "$filename did not return true value";
} else {
+ $! = 0;
return $result;
}
}
walks through @INC and encounters a subroutine, this subroutine gets
called with two parameters, the first a reference to itself, and the
second the name of the file to be included (e.g., "F<Foo/Bar.pm>"). The
-subroutine should return either nothing or else a list of up to three
+subroutine should return either nothing or else a list of up to four
values in the following order:
=over
=item 1
-A filehandle, from which the file will be read.
+A reference to a scalar, containing any initial source code to prepend to
+the file or generator output.
=item 2
+A filehandle, from which the file will be read.
+
+=item 3
+
A reference to a subroutine. If there is no filehandle (previous item),
then this subroutine is expected to generate one line of source code per
call, writing the line into C<$_> and returning 1, then finally at end of
Again, return 1 for each valid line, and 0 after all lines have been
returned.
-=item 3
+=item 4
Optional state for the subroutine. The state is passed in as C<$_[1]>. A
reference to the subroutine itself is passed in as C<$_[0]>.
# sort lexically
@articles = sort @files;
-
+
# same thing, but with explicit sort routine
@articles = sort {$a cmp $b} @files;
-
+
# now case-insensitively
@articles = sort {fc($a) cmp fc($b)} @files;
-
+
# same thing in reversed order
@articles = sort {$b cmp $a} @files;
-
+
# sort numerically ascending
@articles = sort {$a <=> $b} @files;
-
+
# sort numerically descending
@articles = sort {$b <=> $a} @files;
-
+
# this sorts the %age hash by value instead of key
# using an in-line function
@eldest = sort { $age{$b} <=> $age{$a} } keys %age;
-
+
# sort using explicit subroutine name
sub byage {
$age{$a} <=> $age{$b}; # presuming numeric
}
@sortedclass = sort byage @class;
-
+
sub backwards { $b cmp $a }
@harry = qw(dog cat x Cain Abel);
@george = qw(gone chased yz Punished Axed);
# not set here
package main;
@new = sort other::backwards @old;
-
+
# guarantee stability, regardless of algorithm
use sort 'stable';
@new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
-
+
# force use of mergesort (not portable outside Perl 5.8)
use sort '_mergesort'; # note discouraging _
@new = sort { substr($a, 3, 5) cmp substr($b, 3, 5) } @old;
If LENGTH is negative, removes the elements from OFFSET onward
except for -LENGTH elements at the end of the array.
If both OFFSET and LENGTH are omitted, removes everything. If OFFSET is
-past the end of the array, Perl issues a warning, and splices at the
-end of the array.
+past the end of the array and a LENGTH was provided, Perl issues a warning,
+and splices at the end of the array.
The following equivalences hold (assuming C<< $#a >= $i >> )
I<any> contiguous whitespace (not just a single space character) is used as
a separator. However, this special treatment can be avoided by specifying
the pattern S<C</ />> instead of the string S<C<" ">>, thereby allowing
-only a single space character to be a separator.
+only a single space character to be a separator. In earlier Perls this
+special case was restricted to the use of a plain S<C<" ">> as the
+pattern argument to split, in Perl 5.18.0 and later this special case is
+triggered by any expression which evaluates as the simple string S<C<" ">>.
If omitted, PATTERN defaults to a single space, S<C<" ">>, triggering
the previously described I<awk> emulation.
printf "<%s>", "a"; # prints "<a>"
printf "<%6s>", "a"; # prints "< a>"
printf "<%*s>", 6, "a"; # prints "< a>"
- printf "<%*2$s>", "a", 6; # prints "< a>"
+ printf '<%*2$s>', "a", 6; # prints "< a>"
printf "<%2s>", "long"; # prints "<long>" (does not truncate)
If a field width obtained through C<*> is negative, it has the same
but it is intended that this will be possible in the future, for
example using C<.*2$>:
- printf "<%.*2$x>", 1, 6; # INVALID, but in future will print
+ printf '<%.*2$x>', 1, 6; # INVALID, but in future will print
# "<000001>"
=item size
as supported by the compiler used to build Perl:
hh interpret integer as C type "char" or "unsigned
- char" on Perl 5.14 or later
+ char" on Perl 5.14 or later
h interpret integer as C type "short" or
"unsigned short"
- j interpret integer as C type "intmax_t" on Perl
+ j interpret integer as C type "intmax_t" on Perl
5.14 or later, and only with a C99 compiler
(unportable)
l interpret integer as C type "long" or
q, L, or ll interpret integer as C type "long long",
"unsigned long long", or "quad" (typically
64-bit integers)
- t interpret integer as C type "ptrdiff_t" on Perl
+ t interpret integer as C type "ptrdiff_t" on Perl
5.14 or later
- z interpret integer as C type "size_t" on Perl 5.14
+ z interpret integer as C type "size_t" on Perl 5.14
or later
As of 5.14, none of these raises an exception if they are not supported on
use Config;
if ($Config{uselongdouble} eq "define") {
- print "long doubles by default\n";
+ print "long doubles by default\n";
}
It can also be that long doubles and doubles are the same thing:
uses C<$a> for the width, C<$b> for the precision, and C<$c>
as the value to format; while:
- printf "<%*1$.*s>", $a, $b;
+ printf '<%*1$.*s>', $a, $b;
would use C<$a> for the width and precision, and C<$b> as the
value to format.
Portability issues: L<perlport/stat>.
-=item state EXPR
+=item state VARLIST
X<state>
-=item state TYPE EXPR
+=item state TYPE VARLIST
-=item state EXPR : ATTRS
+=item state VARLIST : ATTRS
-=item state TYPE EXPR : ATTRS
+=item state TYPE VARLIST : ATTRS
=for Pod::Functions +state declare and assign a persistent lexical variable
is entered.
See L<perlsub/"Persistent Private Variables"> for details.
+If more than one variable is listed, the list must be placed in
+parentheses. With a parenthesised list, C<undef> can be used as a
+dummy placeholder. However, since initialization of state variables in
+list context is currently not possible this would serve no purpose.
+
C<state> variables are enabled only when the C<use feature "state"> pragma
is in effect, unless the keyword is written as C<CORE::state>.
See also L<feature>.
=for Pod::Functions +current_sub the current subroutine, or C<undef> if not in a subroutine
-A special token that returns the a reference to the current subroutine, or
+A special token that returns a reference to the current subroutine, or
C<undef> outside of a subroutine.
+The behaviour of C<__SUB__> within a regex code block (such as C</(?{...})/>)
+is subject to change.
+
This token is only available under C<use v5.16> or the "current_sub"
feature. See L<feature>.
This function binds a variable to a package class that will provide the
implementation for the variable. VARIABLE is the name of the variable
to be enchanted. CLASSNAME is the name of a class implementing objects
-of correct type. Any additional arguments are passed to the C<new>
+of correct type. Any additional arguments are passed to the
+appropriate constructor
method of the class (meaning C<TIESCALAR>, C<TIEHANDLE>, C<TIEARRAY>,
or C<TIEHASH>). Typically these are arguments such as might be passed
-to the C<dbm_open()> function of C. The object returned by the C<new>
-method is also returned by the C<tie> function, which would be useful
+to the C<dbm_open()> function of C. The object returned by the
+constructor is also returned by the C<tie> function, which would be useful
if you want to access other methods in CLASSNAME.
Note that functions such as C<keys> and C<values> may return huge lists
UNSHIFT this, LIST
SPLICE this, offset, length, LIST
EXTEND this, count
+ DELETE this, key
+ EXISTS this, key
DESTROY this
UNTIE this
BEGIN { require Module; Module->import( LIST ); }
except that Module I<must> be a bareword.
-The importation can be made conditional; see L<if>.
+The importation can be made conditional by using the L<if> module.
In the peculiar C<use VERSION> form, VERSION may be either a positive
decimal fraction such as 5.006, which will be compared to C<$]>, or a v-string
an array; prior to that release, attempting to use an array argument will
produce a syntax error. In scalar context, returns the number of values.
-When called on a hash, the values are returned in an apparently random
-order. The actual random order is subject to change in future versions of
-Perl, but it is guaranteed to be the same order as either the C<keys> or
-C<each> function would produce on the same (unmodified) hash. Since Perl
-5.8.1 the ordering is different even between different runs of Perl for
-security reasons (see L<perlsec/"Algorithmic Complexity Attacks">).
+Hash entries are returned in an apparently random order. The actual random
+order is specific to a given hash; the exact same series of operations
+on two hashes may result in a different order for each hash. Any insertion
+into the hash may change the order, as will any deletion, with the exception
+that the most recent key returned by C<each> or C<keys> may be deleted
+without changing the order. So long as a given hash is unmodified you may
+rely on C<keys>, C<values> and C<each> to repeatedly return the same order
+as each other. See L<perlsec/"Algorithmic Complexity Attacks"> for
+details on why hash order is randomized. Aside from the guarantees
+provided here the exact details of Perl's hash algorithm and the hash
+traversal order are subject to change in any release of Perl.
As a side effect, calling values() resets the HASH or ARRAY's internal
iterator, see L</each>. (In particular, calling values() in void context
Top of form processing is handled automatically: if there is insufficient
room on the current page for the formatted record, the page is advanced by
-writing a form feed, a special top-of-page format is used to format the new
+writing a form feed and a special top-of-page
+format is used to format the new
page header before the record is written. By default, the top-of-page
-format is the name of the filehandle with "_TOP" appended. This would be a
+format is the name of the filehandle with "_TOP" appended, or "top"
+in the current package if the former does not exist. This would be a
problem with autovivified filehandles, but it may be dynamically set to the
format of your choice by assigning the name to the C<$^> variable while
that filehandle is selected. The number of lines remaining on the current
=item when
These flow-control keywords related to the experimental switch feature are
-documented in L<perlsyn/"Switch Statements"> .
+documented in L<perlsyn/"Switch Statements">.
=back