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.
should produceuse 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"; }
END block executed object foo destroyed object bar destroyed
|
|---|