Fellow Monks,

my Google-fu isn’t being too good to me today, so I might be asking something that’s been asked a million times before. Sorry about that.

I have an object, and for various reasons, I’d like to have a DESTROY sub sometimes, but sometimes not. This destructor kills some processes related to this object as a last-minute clean up, but in some situations this is something that wreaks havoc and hence the conditional. So I thought of passing another param to new() and if it’s set, I'd like to bail out from the DESTROY call (return if $self->{no_destroy}). But it turns out that this variable is no longer set by the time we arrive to the DESTROY sub.

Is there anything I could do?


UPDATE: It seems it was a typical brown paper bag-quality 8th layer error. See the reduced code example in response to Corion’s reply, it works just fine.


In reply to Conditional DESTROY by Ralesk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.