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

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

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 wandering the Monastery: (4)
As of 2016-10-24 04:44 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.