summaryrefslogtreecommitdiff
path: root/pod/perlsub.pod
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>1999-09-05 22:07:18 +0000
committerGurusamy Sarathy <gsar@cpan.org>1999-09-05 22:07:18 +0000
commitcd06dffe59d60ee6a2fdd7c81f8cef42c7026b36 (patch)
treebf5d5d4e9d1c11e7d63fd97ce74470e8bedc88d3 /pod/perlsub.pod
parenta2126434f8dd8eabb11a2219137816815758ea93 (diff)
downloadperl-cd06dffe59d60ee6a2fdd7c81f8cef42c7026b36.tar.gz
initial implementation of lvalue subroutines (slightly fixed
version of patch suggested by Ilya Zakharevich, which in turn is based on the one suggested by Tuomas J. Lukka <lukka@iki.fi>) p4raw-id: //depot/perl@4081
Diffstat (limited to 'pod/perlsub.pod')
-rw-r--r--pod/perlsub.pod39
1 files changed, 39 insertions, 0 deletions
diff --git a/pod/perlsub.pod b/pod/perlsub.pod
index 47f507f28d..2beb3dea55 100644
--- a/pod/perlsub.pod
+++ b/pod/perlsub.pod
@@ -611,6 +611,45 @@ Perl will print
The behavior of local() on non-existent members of composite
types is subject to change in future.
+=head2 Lvalue subroutines
+
+B<WARNING>: Lvalue subroutines are still experimental and the implementation
+may change in future versions of Perl.
+
+It is possible to return a modifiable value from a subroutine.
+To do this, you have to declare the subroutine to return an lvalue.
+
+ my $val;
+ sub canmod : lvalue {
+ $val;
+ }
+ sub nomod {
+ $val;
+ }
+
+ canmod() = 5; # assigns to $val
+ nomod() = 5; # ERROR
+
+The scalar/list context for the subroutine and for the right-hand
+side of assignment is determined as if the subroutine call is replaced
+by a scalar. For example, consider:
+
+ data(2,3) = get_data(3,4);
+
+Both subroutines here are called in a scalar context, while in:
+
+ (data(2,3)) = get_data(3,4);
+
+and in:
+
+ (data(2),data(3)) = get_data(3,4);
+
+all the subroutines are called in a list context.
+
+The current implementation does not allow arrays and hashes to be
+returned from lvalue subroutines directly. You may return a
+reference instead. This restriction may be lifted in future.
+
=head2 Passing Symbol Table Entries (typeglobs)
B<WARNING>: The mechanism described in this section was originally