diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-06-17 13:29:04 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-06-17 13:32:58 -0700 |
commit | 4a904372e4d28940f0bcc3b8501925d58b3f0e68 (patch) | |
tree | 61615a52d9e4f65843b6a0f8f415c76b247d9f69 /pod/perlsub.pod | |
parent | 65613fc23b9817bb12168505453c08d1b6b1baf2 (diff) | |
download | perl-4a904372e4d28940f0bcc3b8501925d58b3f0e68.tar.gz |
Doc update for changes in 5.15.0 + tweaks
Diffstat (limited to 'pod/perlsub.pod')
-rw-r--r-- | pod/perlsub.pod | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/pod/perlsub.pod b/pod/perlsub.pod index db398dd723..01c525d069 100644 --- a/pod/perlsub.pod +++ b/pod/perlsub.pod @@ -439,10 +439,12 @@ if you want to stay compatible with releases older than 5.10. =head3 Persistent variables via state() -Beginning with perl 5.9.4, you can declare variables with the C<state> -keyword in place of C<my>. For that to work, though, you must have +Beginning with Perl 5.9.4, you can declare variables with the C<state> +keyword in place of C<my>. For that to work, though, you must have enabled that feature beforehand, either by using the C<feature> pragma, or -by using C<-E> on one-liners. (see L<feature>) +by using C<-E> on one-liners (see L<feature>). Beginning with Perl 5.16, +you can also write it as C<CORE::state>, which does not require the +C<feature> pragma. For example, the following code maintains a private counter, incremented each time the gimme_another() function is called: @@ -740,8 +742,7 @@ To do this, you have to declare the subroutine to return an lvalue. my $val; sub canmod : lvalue { - # return $val; this doesn't work, don't say "return" - $val; + $val; # or: return $val; } sub nomod { $val; @@ -770,14 +771,9 @@ all the subroutines are called in a list context. =item Lvalue subroutines are EXPERIMENTAL -They appear to be convenient, but there are several reasons to be +They appear to be convenient, but there is at least one reason to be circumspect. -You can't use the return keyword, you must pass out the value before -falling out of subroutine scope. (see comment in example above). This -is usually not a problem, but it disallows an explicit return out of a -deeply nested loop, which is sometimes a nice way out. - They violate encapsulation. A normal mutator can check the supplied argument before setting the attribute it is protecting, an lvalue subroutine never gets that chance. Consider; |