in reply to mod-perl and globals

A lot of the scoping issues can be understood by considering that mod_perl wraps you script into a subroutine, and then calls the sub each time you run the script. Sortof. ;)

Are you sure you want to be using globals in the first place? If you are going to clear it anyway, wouldn't using a lexical be a better idea? Or a *cough*object*cough* model? If you really do need a global, you should dive into the mod_perl guide.

I hope that hepls a little... if not, post the code and then I can add more.

update: jjhorner stated it much better.

Paris Sinclair    |    4a75737420416e6f74686572
pariss@efn.org    |    205065726c204861636b6572
I wear my Geek Code on my finger.

Replies are listed 'Best First'.
RE: Re: mod-perl and globals
by ty (Initiate) on Jun 26, 2000 at 12:55 UTC
    Thanks for the reply. All of you. I agree with your suggestions. Here is the catch. I'm using an old bunch of code, about 800-900 lines, that need to be updated to work in mod-perl. It uses globals extensively and in really careless ways. This code uses a common cgi parsing routine that parses the url agrs and dumps them into globals. I want to avoid a total rewrite.

    I'm beginning to understand how mod-perl is handling things. It's different than I thought.

      Have you seen the mod_perl guide section on porting? I have found that if I am faced with 1000 lines of messy code, I can usually rewrite it from scratch in half that, with less effort than it would be to maintain the spaghetti. As St. Larry said:
      "If the burden of decision making is on the programmer, then it's possible for the programmer to make a mess of things. It's possible for Perl programmers to write messy programs. (In case you hadn't noticed.) It's also possible for Perl programmers to write extremely clean, concise, and beautiful programs."
      -- Larry Wall

      If it's ugly, replace it with something beautiful.

      Paris Sinclair    |    4a75737420416e6f74686572
      pariss@efn.org    |    205065726c204861636b6572
      I wear my Geek Code on my finger.