Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^3: if(my) scope

by gwadej (Chaplain)
on Apr 16, 2009 at 17:05 UTC ( #758027=note: print w/ replies, xml ) Need Help??


in reply to Re^2: if(my) scope
in thread if(my) scope

Expanding a bit further.

That comment only applies to mark-and-sweep type garbage collection. As a general rule, Perl's reference-counted garbage collection is deterministic and mostly handles as you would expect. (Present case excepted, of course.)

Personally, I regret the loss of a defined, consistent object lifetime caused by using mark-and-sweep. Having the lifetime of a object determine the timing of events is quite useful. It's one of the reasons I prefer Perl and C++ to Java.

G. Wade


Comment on Re^3: if(my) scope
Re^4: if(my) scope
by ig (Vicar) on Apr 16, 2009 at 22:23 UTC

    case in point:

    package H; sub DESTROY { print "DESTROY\n"; } sub new { my $class = shift; bless {}, $class; } { if(my $h = H->new()) { print "IN\n"; undef $h; } print "\$h out of scope\n"; } print "why now?\n";

    produces:

    IN DESTROY $h out of scope why now?

    As does:

    package H; sub DESTROY { print "DESTROY\n"; } sub new { my $class = shift; bless {}, $class; } { { if(my $h = H->new()) { print "IN\n"; } } print "\$h out of scope\n"; } print "why now?\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://758027]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (17)
As of 2015-07-02 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (36 votes), past polls