perlquestion
eak
Does anyone have any idea why the DESTROY block is not hit in the following example when $foo falls out of scope? If you comment out the line in the nested subroutine, everything works as expected.
<CODE>
#!/usr/bin/perl -w
use strict;
{
package Foo;
$Foo::DCALLS = 0;
sub new { bless {}, shift; }
sub DESTROY {
$Foo::DCALLS++;
warn "DESTROY CALLED";
}
}
{
my $foo = Foo->new;
sub {
print "FOO: $foo\n";
sub {
print "FOO: $foo\n"; # comment this out and the destructor is called
};
};
}
END {
print "DCALLS: $Foo::DCALLS\n";
}
</CODE>