There are a few things you might consider here. One is putting lexicals at a scope where they would be visible to all subs. If you're using Apache::Registry, this will be a problem. This is one reason I don't use Apache::Registry.

You could make them globals. Sometimes that's the most expedient solution. You just need to make sure you re-initialize them on each request.

If they're static constants, you could put them off in some constants package. You still need to make them globals.

However, when people have issues like this it often means they should be using objects. Objects are the standard way of encapsulating a set of data and giving it behaviors, and it sounds like that might be what you're doing.

Finally, you could stick them $r->pnotes(). It's globally accessible through the request object, and it's automatically cleaned up after each request. You can perldoc Apache for the details.


In reply to Re: Thoughts on variable sharing in mod_perl by perrin
in thread Thoughts on variable sharing in mod_perl by IOrdy

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.