Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, I am trying to learn oop by reading perldoc. In perlobj, there is a short code like this:
#!/usr/bin/perl -w #name: monk_perlobj # note: copied from perlobj # purpose: to understand DESTORY block for object package Subtle; sub new { my $test; $test = \$test; warn "CREATING ". \$test; return bless \$test; } sub DESTORY { my $self = shift; warn "DESTORYING $self"; } package main; warn "starting program"; { my $a = Subtle->new; my $b = Subtle->new; $$a = 0; #break selfref warn "leaving block"; } warn "just exited block"; warn "time to die ..."; exit;
and the output is like this;
starting program at ./monk_perlobj line 23. CREATING REF(0x816b8e8) at ./monk_perlobj line 12. CREATING REF(0x81523ec) at ./monk_perlobj line 12. leaving block at ./monk_perlobj line 28. just exited block at ./monk_perlobj line 31. time to die ... at ./monk_perlobj line 32
but the corresponding output from perlobj actually has two other lines from the destructor block. Could someone tell me why I am not able to see them? Is it related how perl was bulit and how can I check it. thanks very much indeed.

Replies are listed 'Best First'.
Re: about destructor
by Ultra (Hermit) on Oct 24, 2005 at 16:04 UTC

    There's a typo ....

    Shouldn't

    sub DESTORY { my $self = shift; warn "DESTORYING $self"; }
    be
    sub DESTROY { my $self = shift; warn "DESTROYING $self"; }
    ?

    Dodge This!

      Kinda makes me wonder what de-storying an object really does, though.