in reply to DESTROY problem

I don't know anything about how DESTROY works, but I think your code above may be suffering from a name-space collision with the B module that provides access to the Perl Compiler Backend

Replies are listed 'Best First'.
Re^2: DESTROY problem
by AnomalousMonk (Archbishop) on Dec 31, 2010 at 18:38 UTC

    My understanding is that a module must be explicitly (Update: although perhaps indirectly) loaded via use, require or do for any name collision to occur.

    The example code of the OP seems to have been changed in some way to make it 'clearer', and the exact invocation of the program is not given, but no such loading of the B module seems to have been done, so no name collision could happen.

      See this
      $ perl -le"print for grep /^\w+::/, keys %:: version:: Tie:: utf8:: re:: CORE:: DynaLoader:: mro:: Win32CORE:: attributes:: Regexp:: UNIVERSAL:: main:: Win32:: PerlIO:: IO:: Internals:: DB::
      Its not inconceivable that B could be loaded without an explicit use B;

        I get the same output if I change the class name:

        use strict; use warnings; use 5.010; {package Dog; sub new { my $class = shift; bless {}, $class; } sub DESTROY { my $self = shift; say "destroy"; $self->SUPER::DESTROY; } } my $d = Dog->new; --output:-- destroy (in cleanup) Can't locate object method "DESTROY" via package +"Dog" at perl2.pl line 16.

        I ran the program like this:

        C:\Users\Me\Documents>perl perl2.pl

        I'll follow JavaFan's instructions--rather than Randall Scwhartz's.