Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2014-07-31 20:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (252 votes), past polls