http://qs321.pair.com?node_id=124449

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

It seems Perl is cleaning up in "the wrong order" on my WinNT Perl 5.6.0 system. Below is a section of code from a module. The constructor creates a Win32::OLE object and stores a reference to it. When the destructor is called, that object is apparently already destroyed. I'm not sure how this can legitimately happen, as the module's instance data still holds a reference to the OLE object.

At the suggestion of someone in the CB (sorry... forgot who) I tried adding a global reference to the OLE object as an experiment to see if that would keep it around. That didn't seem to help.

What am I missing? Is there a way to make this work? Or am I barking up the wrong tree?

use Win32::OLE; sub new { # fileName my $self = {}; bless $self, shift; $self->{excel} = Win32::OLE->new("Excel.Application") or croak "Ca +n't start Excel: ", Win32::OLE->LastError, "\n"; return $self; } sub disconnect { my $self = shift; $self->{excel}->Quit if $self->{excel}; }