The reason is simple , lexicals (my) are destroyed/destructored/cleanedup in-order

Where as, globals are cleaned up during "global destruction" before program exits but not in-order as there is no order they're globals

You can short-circuit cleanup with POSIX::exit() for even faster exit, but then destructors and stuff dont ...

Example

## $stuff not exist { our $stuff = 1234; } ## $stuff still exist { my $lexi = 1234; } ## $lexi cleaned up here but $stuff still exists { my $flexi = 1234; } ## $flexi cleanedup but stuff still exists exit; ## $stuff cleaned up here in whatever fast order it happens to come fr +om the perl memory stack

There are discussions on this just search for global destruction order, site:perlmonks.org global destruction order

see sub DESTROY: Strange ordering of object destruction (global destruction order not guaranteed, Re^3: when is destroy function called ( perl -d:Trace dalek ), Re^2: Perl Gtk2 - ->destroy() is Not Causing the Script to Exit

Why does Perl have this odd behavior during cleanup?

Heheh, its always funny when people (me too) say something is odd/weird ... almost as if they're trying to say I know stuff but this doesn't behave like it should (i used to think this but I know better now)... but what they really mean is always I don't know what should be happening, why is there a difference in what is happening, even if they don't think this is what they mean


In reply to Re: my versus our, why is my slower when script ends (global cleanup) by Anonymous Monk
in thread my versus our, why is my slower when script ends (global cleanup) by marioroy

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.