196

Object Oriented Perl-gramming
Destructors

  • A destructor method is simply a member function (subroutine) named DESTROY which will be automatically called

    • When the object reference's variable goes out of scope

    • When the object reference's variable is undef-ed

    • When the script terminates

    • When the perl interpreter terminates

  • For example
      package MyClass;
      ...
      sub DESTROY
      {
          print "   MyClass::DESTROY called\n";
      }