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

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

Thread Previous | Thread Next
Eric Brine
November 17, 2009 15:23
Re: [perl #67838] lvalue substr keeping lexical alive
Message ID:
On Tue, Nov 17, 2009 at 2:27 PM, David Nicol <> wrote:

> 1: are there situations where a RAIL object will be the subject of one of
> these functions?
> (resource acquisition is locking is the big design pattern that relies on
> timely destruction)


I previously gave the following example which demonstrates resources being
help until global destruction (marked by "G")  rather than being released

# Timely release
>perl -le"{ my $x=''; $x = bless {}; } print 'G'; DESTROY { print 'D' }"

# Resource held until global destruction
>perl -le"{ my $x=''; vec($x,0,1)=0; $x = bless {}; } print 'G'; DESTROY {
print 'D' }"

Here's an example that uses lvalue keys(%h) in the most straightforward

perl -le'
    sub init {
        my %h;
        keys(%h) = @_;
        %h = map { $_ => bless {} } @_;
        return \%h;
    DESTROY { print "D" }
    { my $h = init(qw(a b c)); }
    print "G";

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.

What's wrong with that suggestion?

The only downside is overhead. It makes yet another variable magical (the
var passed as an arg). I can write up a patch tonight if you wish.

Should I only use weaken when necessary (lvalue subs)?

When does TARG hold the last reference to something,

See the reply to your first question.

can TARG manipulation stuff simply leave reference counts alone?

If these ops couldn't be used as the return value for lvalue subs, I believe
we could do forgo ref counting. I don't think that's a condition we can


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About