develooper Front page | perl.perl5.porters | Postings from November 2009

Re: [perl #67838] lvalue substr keeping lexical alive

Thread Previous | Thread Next
From:
Eric Brine
Date:
November 17, 2009 22:07
Subject:
Re: [perl #67838] lvalue substr keeping lexical alive
Message ID:
f86994700911172206o15848bf4te49b21fe5b2341e1@mail.gmail.com
On Tue, Nov 17, 2009 at 6:22 PM, Eric Brine <ikegami@adaelis.com> wrote:

> On Tue, Nov 17, 2009 at 2:27 PM, David Nicol <davidnicol@gmail.com> wrote:
>
>> 2: can TARG be a weak reference using current weak reference technology?
>>
> That was mentioned earlier in this thread, and seems from a high and
>> distant
>> level to be the way to go.
>>
>
> Yes, I believe so.
>

No, I was wrong. Conditions that must be met:

   - A magical var (e.g. PVLV) must be returned.
   - The magical var cannot be a TEMP
   - The magical var must reference the arg var
   - The magical var must have a counted reference to the arg var.

If the TARG is a PLVL that targets an RV that weekly references the arg var,
it violates the fourth point causing the following to fail:

my $r; { my $s = ""; $r = \substr($s, 0, 1); } $$r = 'a'; print $$r;

If the TARG is an RV that weekly references a PVLV that references the arg
var, the PVLV would be a TEMP. That violates the second causing the
following to fail:

sub :lvalue { my $s = ""; substr($s, 0, 1) }->();

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