I thought it was as easy as:
local *private::package::; # time passes $saved{$some_name} = \*private::package::;
but I was wrong.

As for the underlying question though, your description of what you are doing sets off warning flags for me. Why not scoop out the body of the scripts into modules, turn the scripts into wrappers, and then call the module in your code? What if a script makes an assumption and does something like call exit? Why do you need to have the globals in your current package, can you redesign to not need that? If you have any control over what globals you need from the script, why not eval each script into its own package, then in your second loop alias just the globals that you need from the scripts?

The exit question is a serious gotcha. The other suggestions are alternate ways of solving your likely problem. I have found valid uses for all of the other suggestions. The one with each getting their own package was for configuration loading - there are very few other places where I would even consider that. The idea of scooping things into modules is my first recommendation.

Now there could be things I don't know that make all of these ideas bad. But my gut feeling is that you don't need to use your current design, and that using it you will run into further issues - it just smells like a bad hack.


In reply to RE (tilly) 3: package namespace manipulation by tilly
in thread package namespace manipulation by knight

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.