in reply to Thoughts on variable sharing in mod_perl

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.

  • Comment on Re: Thoughts on variable sharing in mod_perl

Replies are listed 'Best First'.
Re: Re: Thoughts on variable sharing in mod_perl
by IOrdy (Friar) on Aug 23, 2001 at 07:29 UTC
    ++ perrin, you where spot on. I'm using Apache::Request and so even when I declare a variable that would normally still be in the same scope as the sub I get these problems.

    I think a package of constants sounds like the best solution so I'll start on that.

    I've been avoiding OO until I get a little more comfortable with perl (seeing as this is my first project I've written).
      You dont need any OO for this... A normal module will do just fine...
      package Config; use strict; my %config = { #Init your variables in %config }; 1;
      in your apache/perl startup file (the one you call from httpd.conf. You do have such a file right???) you write use Config; And your config will be avail to all script in $Config::config.... Or you could do something similar with constants...

      T I M T O W T D I