Mark Anderson wrote at Thu, 06 Jun 2002 18:48:32 +0200:
> I came across a reference to lvalue(s) in
> perldoc -f substr
> I then searched perldoc for "lvalue", and looked at each reference in:
> perldoc perldiag
> perldoc perltoc
> perldoc perlfunc
> perldoc perlsub
> perldoc perlop
> perldoc perlguts
> perldoc perlsyn
> perldoc perlfaq7
> perldoc perlfaq4
> perldoc perlref
>
Well, the documentation is a really a little bit hidden.
You can find it in perlsub.
Here are some lines from it:
Lvalue subroutines
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.
Cheerio,
Janek
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]