Fellow Monks,

I have a fairly large Perl application for which I need to reduce the memory size (program is currently at 10M/process on my Win32 box; multiple processes may run the program). This program is naturally broken down into several packages, all of which are 'use'd at the top of the starting Perl file; e.g.

use Alpha; use Beta; use Gamma; use Delta;
Of course, the Alpha package itself 'use's a bunch of other packages, which in turn use other packages, etc. So Alpha might begin with something like
package Alpha; use Rho; use Sigma; use Tau; use Delta;
However, a lot of these packages are never used, depending on the many arguments that the user can pass in at runtime. For instance, Alpha and Beta are mutually exclusive. I thus replaced the first section of code with something like
use Gamma; use Delta; # Argument parsing here if ([user specified Beta]) { require Beta; import Beta; # make Beta calls } else { require Alpha; import Alpha; # make Alpha calls }
This save me around a half meg of RAM. Coolness. I'd like to be able to employ similar logic on all my packages. I thus need for any other package required by my program to be able to access the hash in the main namespace, which is where those command line options are currently being stored. Does anyone know of a way to do this, or another approach I can use to solve this problem? I've considered shoving the data into %INC or the like, but this seems pretty hacky and fairly error-prone.

Any help would be appreciated.

-Ton
-----
Be bloody, bold, and resolute; laugh to scorn
The power of man...


In reply to Inter-package communication by ton

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.