I'm guessing this is a bug.

It is a known behaviour, Perl's "global destruction" phase doesn't obey reference counts, and the order of destruction isn't guaranteed , so $perldata gets destroyed before $c/$b,

The solution to this kind of thing is to arrange for global objects to get destroyed before and to use weak references

use DBI; $perldata = bless { hello => 'world' }, 'superman' ; @ARGV and $perldata = { hello => 'world' } ; sub test { my( $o, $v ) = @_; my $m = bless { v => $v, perldata => $o }, 'TQIS::test' ; warn "$m $$m{v}"; return $m ; } sub TQIS::test::DESTROY { my $self = shift ; warn "$self $$self{v} => $$self{perldata} "; } $a = test( $perldata , 'a') ; $b = test( $perldata , 'b' ) ; $c = test( $perldata , 'c' ) ; __END__ $ perl junk TQIS::test=HASH(0x3f8b5c) a at junk line 9. TQIS::test=HASH(0x99a88c) b at junk line 9. TQIS::test=HASH(0xa57854) c at junk line 9. TQIS::test=HASH(0xa57854) c => at junk line 15 during global destruc +tion. TQIS::test=HASH(0x99a88c) b => at junk line 15 during global destruc +tion. TQIS::test=HASH(0x3f8b5c) a => superman=HASH(0x3f8a7c) at junk line 1 +5 during global destruction. $ perl junk --nobless TQIS::test=HASH(0x99a43c) a at junk line 9. TQIS::test=HASH(0x99a97c) b at junk line 9. TQIS::test=HASH(0xa576a4) c at junk line 9. TQIS::test=HASH(0xa576a4) c => HASH(0x3f8d04) at junk line 15 during +global destruction. TQIS::test=HASH(0x99a97c) b => HASH(0x3f8d04) at junk line 15 during +global destruction. TQIS::test=HASH(0x99a43c) a => HASH(0x3f8d04) at junk line 15 during +global destruction.

See also Re: sub DESTROY: Strange ordering of object destruction


In reply to Re: use Switch wierdness by Anonymous Monk
in thread use Switch wierdness by tqisjim

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.