Re: This Week on perl5-porters (21-27 April 2003)

Enache Adrian <[email protected]> Tue, 29 Apr 2003 06:57:08 +0300
Newsgroups gmane.comp.lang.perl.perl5-summary
Message-ID <[email protected]>
On Mon, Apr 28, 2003 at 10:51:31PM +0200, Rafael Garcia-Suarez wrote:
> Localization of lvalues
>   simply. Rafael, noticing that other lvalues can be localized (e.g. "pos"
>   or "substr", although not very reliably sometimes), thinks this should
>   be fixed to work. Hugo, however, says that the most we can do is to add

localizing substr is always bogus, and may be even harmful somehow.

this

$x="xxx"; { local substr($x,1,1) = "y" }

localizes $x - ie. sets it to undef.

But someone may try to find the cause why $x is void elsewhere - and
letting him do so isn't fair :)

So here is my patchlet from then. A warning may be good too, until
localizing that return value will do something useful.

Regards,
Adi

----------------------------------------------------------------
--- /arc/bleadperl/op.c	2003-04-17 00:25:36.000000000 +0300
+++ bleadperl/op.c	2003-04-29 04:11:05.000000000 +0300
@@ -1141,7 +1141,7 @@ Perl_mod(pTHX_ OP *o, I32 type)
 	pad_free(o->op_targ);
 	o->op_targ = pad_alloc(o->op_type, SVs_PADMY);
 	assert(SvTYPE(PAD_SV(o->op_targ)) == SVt_NULL);
-	if (o->op_flags & OPf_KIDS)
+	if (o->op_flags & OPf_KIDS && type)
 	    mod(cBINOPo->op_first->op_sibling, type);
 	break;