From: Rafael Garcia-Suarez Date: Thu, 6 Jul 2006 13:36:57 +0000 (+0000) Subject: Mention state variables in perldiag. Add switch-related keywords X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=36fb85f3330d45eeaf9d312c267fad71d5354c6c;p=p5sagit%2Fp5-mst-13.2.git Mention state variables in perldiag. Add switch-related keywords in the keyword listing section in perlfunc. Add a summary of C in perlfunc. Fix a typo in the synopsis for C. Don't say that C is illegal in perlsub. p4raw-id: //depot/perl@28491 --- diff --git a/pod/perldiag.pod b/pod/perldiag.pod index 93c8767..8228cf9 100644 --- a/pod/perldiag.pod +++ b/pod/perldiag.pod @@ -1422,13 +1422,18 @@ conditional. Some people have exploited this bug to achieve a kind of static variable. Since we intend to fix this bug, we don't want people relying on this behavior. You can achieve a similar static effect by declaring the variable in a separate block outside the function, eg - + sub f { my $x if 0; return $x++ } becomes { my $x; sub f { return $x++ } } +Beginning with perl 5.9.4, you can also use C variables to +have lexicals that are initialized only once (see L): + + sub f { state $x; return $x++ } + =item DESTROY created new reference to dead object '%s' (F) A DESTROY() method created a new reference to the object which is diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 41f19a8..180c481 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -158,19 +158,23 @@ C, C, C, C, C, C, C =item Keywords related to switch -C, C +C, C, C, C, C (These are only available if you enable the "switch" feature. See L and L.) =item Keywords related to scoping -C, C, C, C, C, C, C +C, C, C, C, C, C, C, +C + +(C is only available if the "state" feature is enabled. See +L.) =item Miscellaneous functions -C, C, C, C, C, C, C, C, -C, C, C +C, C, C, C, C, C, C, +C, C, C, C, C =item Functions for processes and process groups X X X @@ -229,8 +233,10 @@ X C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, +C, C, C, C, C, C, C, C, -C*, C, C, C, C, C, C, C +C*, C, C, C, C, C, C, C, +C, C, C, C, C * - C was a keyword in perl4, but in perl5 it is an operator, which can be used in expressions. @@ -3429,7 +3435,7 @@ See L and L for more about Unicode. =item our EXPR X X -=item our EXPR TYPE +=item our TYPE EXPR =item our EXPR : ATTRS @@ -5957,6 +5963,23 @@ See your native chmod(2) and stat(2) documentation for more details about the C constants. To get status info for a symbolic link instead of the target file behind the link, use the C function. +=item state EXPR +X + +=item state TYPE EXPR + +=item state EXPR : ATTRS + +=item state TYPE EXPR : ATTRS + +C declares a lexically scoped variable, just like C does. +However, those variables will be initialized only once, contrary to +lexical variables that are reinitialized each time their enclosing block +is entered. + +C variables are only enabled when the C pragma is +in effect. See L. + =item study SCALAR X diff --git a/pod/perlsub.pod b/pod/perlsub.pod index 71d6691..082d520 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -394,7 +394,6 @@ never fully qualified with the package name. In particular, you're not allowed to try to make a package variable (or other global) lexical: my $pack::var; # ERROR! Illegal syntax - my $_; # also illegal (currently) In fact, a dynamic variable (also known as package or global variables) are still accessible using the fully qualified C<::> notation even while a