Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

autoflush and 'DESTROY'

by Chady (Priest)
on Mar 16, 2002 at 20:27 UTC ( [id://152229]=perlquestion: print w/replies, xml ) Need Help??

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

fellow monks, here's the set-up:

index.pl is running and at a time it will gather and eval the string:

$string = 'require ./scripts/eliza.pl'; eval "$string";

now at eliza.pl I have this:

$|++; use Chatbot::Eliza; ## do something with eliza...

Now if I run this I get the following warning message:

[Sat Mar 16 21:44:55 2002] C:\Inetpub\wwwroot\index.pl: (in cleanup) C +an't access `DESTROY' field in object of class Chatbot::Eliza : [Sat +Mar 16 21:44:55 2002] C:\Inetpub\wwwroot\index.pl: at ./scripts/eliza +.pl line 34

the problem goes away if I remove the autoflush $|++ line. Can someone explain to me why is this happening?


He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

Chady | http://chady.net/

Replies are listed 'Best First'.
Re: autoflush and 'DESTROY'
by tachyon (Chancellor) on Mar 16, 2002 at 20:44 UTC

    Add the line:

    sub DESTROY {}

    to the Chatbot::Eliza code to fix the warning. For some background on DESTROY see Object scope and DESTROY

    From perlman:perltoot:

    Destruction happens automatically via Perl's garbage collection (GC) system, which is a quick but somewhat lazy reference-based GC system. To know what to call, Perl insists that the destructor be named DESTROY. Perl's notion of the right time to call a destructor is not well-defined currently, which is why your destructors should not rely on when they are called.

    Evidently autoflush is altering when DESTROY is called. I recall reading somewhere that you should include a DESTROY() method to avoid warnings like this but can't remember where for the life of me.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      to the Chatbot::Eliza code to fix the warning.

      You don't have to modify the module itself for this. Changing the module will bite you when upgrading it.

      sub Chatbot::Eliza::DESTROY { }

      U28geW91IGNhbiBhbGwgcm90MTMgY
      W5kIHBhY2soKS4gQnV0IGRvIHlvdS
      ByZWNvZ25pc2UgQmFzZTY0IHdoZW4
      geW91IHNlZSBpdD8gIC0tIEp1ZXJk
      

        Or perhaps the more obscure

        *{Chatbot::Eliza::DESTROY} = sub {};

        Have you considered a job with M$ ? Patching the source of the problem and informing the author is better than working around the error IMHO

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://152229]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-23 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found