On Fri, Jan 12, 2001 at 08:51:36PM -0800, Stephen McCamant wrote: > >>>>> "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. Sure. > 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, Still? Ah, okay. (Although you say 'current' I suspect that it would be very hard to change that without breaking any code that's playing with list context.) > 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). I'd *far* rather that lvalue-calls-in-list-context were simply made illegal (fatal errors). That way a) people won't be confused by the less than obvious `current' semantics, and b) the way would be clear to 'fix' list-context lvalue calls later without having to worry about breaking old code. Tim.Thread Previous