Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Global destruction feature / bug ?

by ikegami (Pope)
on Apr 03, 2008 at 19:05 UTC ( #678245=note: print w/ replies, xml ) Need Help??

in reply to Global destruction feature / bug ?

When the scope (the file) ends, the last reference to $foo is released, so it's detroyed.

If any function (incl END) referenced $foo, it would capture the variable. In that case, there would still be a reference to the variable at the end of the file scope, so the variable will survive until global destruction.

use strict; use warnings; sub Foo::DESTROY{ print "object $_[0]->[0] destroyed\n"; } my $foo = bless [ 'foo' ], 'Foo'; # notice 'my' our $bar = bless [ 'bar' ], 'Foo'; # notice 'our' END { $foo; print "END block executed\n"; }
should produce
END block executed object foo destroyed object bar destroyed

Comment on Re: Global destruction feature / bug ?
Select or Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2015-11-28 14:44 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (742 votes), past polls