develooper Front page | perl.perl5.porters | Postings from January 2001

Re: [PATCH @8404] Consolidated lvalue sub changes

Thread Previous | Thread Next
From:
Stephen McCamant
Date:
January 12, 2001 20:52
Subject:
Re: [PATCH @8404] Consolidated lvalue sub changes
Message ID:
14943.54780.664524.189374@soda.csua.berkeley.edu
>>>>> "TB" == Tim Bunce <Tim.Bunce@ig.co.uk> writes:

TB> On Wed, Jan 10, 2001 at 09:36:51PM -0800, Stephen McCamant wrote:

SMcC> =item Can't return %s to lvalue scalar context

SMcC> (F) You tried to return a complete array or hash from an lvalue
SMcC> subroutine, but you called the subroutine in a way that made
SMcC> Perl think you meant to return only one value. You probably
SMcC> meant to write parentheses around the call to the subroutine,
SMcC> which tell Perl that the call should be in list context.

TB> But
TB> 	(sub_returning_lvalue_hash()) = 1;

TB> would be rather odd and, I hope, generate an 'odd number of elements in
TB> hash assignment' error.

It's a warning rather than an error, but yes.

TB> And
TB> 	(sub_returning_lvalue_array()) = 1;

TB> could perhaps be better written as
	
TB> 	sub_returning_lvalue_array() = (1);

TB> (I'm not sure if that'll work as I'd expect, I've not been following
TB> too closely.)

No, unfortunately it won't work as you expect. The current operation
of lvalue subroutines follows the same rules as for scalars, which
means the operative difference is the presence or absence of parens on 
the left side. (Just like `$x = (1, 2, 3)' is still a scalar
assignment).

TB> So I'd suggest that the docs suggest writing parentheses around
TB> the _value_ rather than the call.

I'm not particularly fond of the current lvalue subroutine context
semantics, but I don't really have anything better to suggest (except
maybe always forcing list context, but that seems like a step
backwards).

 -- Stephen McC 

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About