You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Keith G. Murphy" <ke...@mindspring.com> on 2000/08/03 02:09:09 UTC

Why do variables not reinitialize when script changed?

This is probably a very basic question, understood by everyone but...

Why, when I change a script loaded under Apache::Registry, and the
script (verifiably) reloads, do global variables not reinitialize?

I'm running Apache 1.3.9, mod_perl 1.21 on a Debian GNU/Linux system.

Am I the only one that finds it odd that the variables hang around
unchanged when the script that they pertain to is recompiled?

Perhaps this is stated or implied in the documentation; I didn't see it.

Re: Why do variables not reinitialize when script changed?

Posted by Stas Bekman <st...@stason.org>.
On Thu, 3 Aug 2000, ___cliff rayman___ wrote:

> 
> Stas Bekman wrote:
> 
> > On Thu, 3 Aug 2000, ___cliff rayman___ wrote:
> >
> > > "Keith G. Murphy" wrote:
> > >
> > > > ___cliff rayman___ wrote:
> > > > >
> > > > > The perl interpreter has a one global symbol table called the stash where
> > > > > all global variables are referenced by package and by variable name.
> > > > > Since the interpreter does not go away when a script is recompiled, neither
> > > > > does the stash or any of the items contained within it.  Some programmers
> > > > > are probably using this as a feature, and therefore it is unlikely that it
> > > > > will change.
> > > > > This is really standard perl stuff and it has nothing to do with
> > > > > Apache::Registry in particular.  It is just something the average perl
> > > > > programmer does not come across since we usually load the interpreter, load
> > > > > a program, run the program, exit the interpreter.
> > > > >
> > > > > check out:
> > > > > http://thingy.kcilink.com/modperlguide/porting/Global_Variables_Persistence.html
> > > > >
> > > > Thanks for the info and the link.
> > > >
> > > > One note though.  The info in the link really doesn't pertain to my
> > > > specific question:
> > > >
> > > > "global variables persist inside the same process from request to
> > > > request"
> > > >
> > > > I knew that; I was surprised that they did even on a recompilation of
> > > > the script, which the link info doesn't really refer to.
> > >
> > > i will see if i can find a good place in the guide to add it and i'll send stas the
> > > patch.
> >
> > I'm not sure there is a need for a patch. I think you confuse,
> > something. When the script is recompiled all the variables belonging to
> > the package decalared by Apache::Registry or similar are getting reset. If
> > you require/use() some modules that declare packages and have global
> > variables -- these won't be reset unless reloaded or initialized in your
> > code.
> 
> i am not sure i was crystal clear on that - thanks.  we might want to add something about
> all of this to the guide however to make it all perfectly clear.  OR, maybe it is in there
> and i have just not come across it yet.  i am making my full sweep through the guide now.

Well, it's a Perl issue. And as far as my memory stretches, this issue has
never come up on the list. I tend to document widely encountered problems
with Perl use under mod_perl. If I'd commit myself adding to the guide
every problem someone ever had with Perl while using mod_perl the guide
won't be 600+ pages but 6000+ pages. Remember that the bigger
documentation is the harder it to navigate and to find the answer to
really common problems people encounter daily.

Therefore, unless this issue comes up again in the future, I see no reason
to document this minor thing. 

I hope that Keith has solved his problem though.

_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://perl.org     http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org



Re: Why do variables not reinitialize when script changed?

Posted by ___cliff rayman___ <cl...@genwax.com>.
Stas Bekman wrote:

> On Thu, 3 Aug 2000, ___cliff rayman___ wrote:
>
> > "Keith G. Murphy" wrote:
> >
> > > ___cliff rayman___ wrote:
> > > >
> > > > The perl interpreter has a one global symbol table called the stash where
> > > > all global variables are referenced by package and by variable name.
> > > > Since the interpreter does not go away when a script is recompiled, neither
> > > > does the stash or any of the items contained within it.  Some programmers
> > > > are probably using this as a feature, and therefore it is unlikely that it
> > > > will change.
> > > > This is really standard perl stuff and it has nothing to do with
> > > > Apache::Registry in particular.  It is just something the average perl
> > > > programmer does not come across since we usually load the interpreter, load
> > > > a program, run the program, exit the interpreter.
> > > >
> > > > check out:
> > > > http://thingy.kcilink.com/modperlguide/porting/Global_Variables_Persistence.html
> > > >
> > > Thanks for the info and the link.
> > >
> > > One note though.  The info in the link really doesn't pertain to my
> > > specific question:
> > >
> > > "global variables persist inside the same process from request to
> > > request"
> > >
> > > I knew that; I was surprised that they did even on a recompilation of
> > > the script, which the link info doesn't really refer to.
> >
> > i will see if i can find a good place in the guide to add it and i'll send stas the
> > patch.
>
> I'm not sure there is a need for a patch. I think you confuse,
> something. When the script is recompiled all the variables belonging to
> the package decalared by Apache::Registry or similar are getting reset. If
> you require/use() some modules that declare packages and have global
> variables -- these won't be reset unless reloaded or initialized in your
> code.

i am not sure i was crystal clear on that - thanks.  we might want to add something about
all of this to the guide however to make it all perfectly clear.  OR, maybe it is in there
and i have just not come across it yet.  i am making my full sweep through the guide now.

>
>
> > > *You* have straightened me out, on the other hand.
> > >
> > > So, lessee, BEGIN { somevar=somevalue; } ought to work for a variable I
> > > want reinitialized at compilation only...
>
> Not if you are talking about the scripts running under Apache::Registry
> and friends, please read the guide.
> http://perl.apache.org/guide/porting.html#BEGIN_blocks
>

--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/



Re: Why do variables not reinitialize when script changed?

Posted by Stas Bekman <st...@stason.org>.
On Fri, 4 Aug 2000, Keith G. Murphy wrote:

> Stas Bekman wrote:
> >  
> > I think you confuse,
> > something. When the script is recompiled all the variables belonging to
> > the package decalared by Apache::Registry or similar are getting reset. If
> > you require/use() some modules that declare packages and have global
> > variables -- these won't be reset unless reloaded or initialized in your
> > code.
> 
> OK, we've lost my original question here, but what I was saying was
> this:
> 
> I have a script that is in Apache::Registry.  (It's showing up in
> "Compiled Registry Scripts" in perl-status).
> 
> The global variables are *not* getting set on recompilation.  Are you
> saying they should?

In your original email you've said that the variables don't get reset on
recompilation.

The variables are set when you set them, either every time in the script
when this executed, or in the BEGIN block once as you have mentioned
below (under Apache::Registry).

> > > > *You* have straightened me out, on the other hand.
> > > >
> > > > So, lessee, BEGIN { somevar=somevalue; } ought to work for a variable I
> > > > want reinitialized at compilation only...
> > 
> > Not if you are talking about the scripts running under Apache::Registry
> > and friends, please read the guide.
> > http://perl.apache.org/guide/porting.html#BEGIN_blocks
> > 
> Stas, what are you talking about?  Your own guide says:
> 
> "BEGIN blocks in Apache::Registry scripts will be executed, as above
> plus: 
> 		...
> An additional time, once per child process, each time the script file
> changes on disk. "
> 
> I.e., at compilation.  And that is what I'm seeing, and it's the
> behavior I want.
> 
> I think you are confused about what I am saying.  Probably working too
> much on the template guide...  :-)

Brrgghhh,  I guess we were talking about different things.... I thought
you were trying to initialize in the code. Apparently I misread your
quote. Sorry about that.

Never mind, BEGIN { somevar=somevalue; } does what you want, great!!!


_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://perl.org     http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org



Re: Why do variables not reinitialize when script changed?

Posted by "Keith G. Murphy" <ke...@mindspring.com>.
Stas Bekman wrote:
>  
> I think you confuse,
> something. When the script is recompiled all the variables belonging to
> the package decalared by Apache::Registry or similar are getting reset. If
> you require/use() some modules that declare packages and have global
> variables -- these won't be reset unless reloaded or initialized in your
> code.

OK, we've lost my original question here, but what I was saying was
this:

I have a script that is in Apache::Registry.  (It's showing up in
"Compiled Registry Scripts" in perl-status).

The global variables are *not* getting set on recompilation.  Are you
saying they should?
> 
> > > *You* have straightened me out, on the other hand.
> > >
> > > So, lessee, BEGIN { somevar=somevalue; } ought to work for a variable I
> > > want reinitialized at compilation only...
> 
> Not if you are talking about the scripts running under Apache::Registry
> and friends, please read the guide.
> http://perl.apache.org/guide/porting.html#BEGIN_blocks
> 
Stas, what are you talking about?  Your own guide says:

"BEGIN blocks in Apache::Registry scripts will be executed, as above
plus: 
		...
An additional time, once per child process, each time the script file
changes on disk. "

I.e., at compilation.  And that is what I'm seeing, and it's the
behavior I want.

I think you are confused about what I am saying.  Probably working too
much on the template guide...  :-)

Re: Why do variables not reinitialize when script changed?

Posted by Stas Bekman <st...@stason.org>.
On Thu, 3 Aug 2000, ___cliff rayman___ wrote:

> "Keith G. Murphy" wrote:
> 
> > ___cliff rayman___ wrote:
> > >
> > > The perl interpreter has a one global symbol table called the stash where
> > > all global variables are referenced by package and by variable name.
> > > Since the interpreter does not go away when a script is recompiled, neither
> > > does the stash or any of the items contained within it.  Some programmers
> > > are probably using this as a feature, and therefore it is unlikely that it
> > > will change.
> > > This is really standard perl stuff and it has nothing to do with
> > > Apache::Registry in particular.  It is just something the average perl
> > > programmer does not come across since we usually load the interpreter, load
> > > a program, run the program, exit the interpreter.
> > >
> > > check out:
> > > http://thingy.kcilink.com/modperlguide/porting/Global_Variables_Persistence.html
> > >
> > Thanks for the info and the link.
> >
> > One note though.  The info in the link really doesn't pertain to my
> > specific question:
> >
> > "global variables persist inside the same process from request to
> > request"
> >
> > I knew that; I was surprised that they did even on a recompilation of
> > the script, which the link info doesn't really refer to.
> 
> i will see if i can find a good place in the guide to add it and i'll send stas the
> patch.

I'm not sure there is a need for a patch. I think you confuse,
something. When the script is recompiled all the variables belonging to
the package decalared by Apache::Registry or similar are getting reset. If
you require/use() some modules that declare packages and have global
variables -- these won't be reset unless reloaded or initialized in your
code. 

> > *You* have straightened me out, on the other hand.
> >
> > So, lessee, BEGIN { somevar=somevalue; } ought to work for a variable I
> > want reinitialized at compilation only...

Not if you are talking about the scripts running under Apache::Registry
and friends, please read the guide.
http://perl.apache.org/guide/porting.html#BEGIN_blocks

> i will also add the solution to my guide revisioins.  :-)
> 
> >
> >
> > Yep, works.  Thanks.
> 
> --
> ___cliff rayman___cliff@genwax.com___http://www.genwax.com/
> 
> 
> 



_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide 
mailto:stas@stason.org   http://perl.org     http://stason.org/TULARC
http://singlesheaven.com http://perlmonth.com http://sourcegarden.org



Re: Why do variables not reinitialize when script changed?

Posted by ___cliff rayman___ <cl...@genwax.com>.
"Keith G. Murphy" wrote:

> ___cliff rayman___ wrote:
> >
> > The perl interpreter has a one global symbol table called the stash where
> > all global variables are referenced by package and by variable name.
> > Since the interpreter does not go away when a script is recompiled, neither
> > does the stash or any of the items contained within it.  Some programmers
> > are probably using this as a feature, and therefore it is unlikely that it
> > will change.
> > This is really standard perl stuff and it has nothing to do with
> > Apache::Registry in particular.  It is just something the average perl
> > programmer does not come across since we usually load the interpreter, load
> > a program, run the program, exit the interpreter.
> >
> > check out:
> > http://thingy.kcilink.com/modperlguide/porting/Global_Variables_Persistence.html
> >
> Thanks for the info and the link.
>
> One note though.  The info in the link really doesn't pertain to my
> specific question:
>
> "global variables persist inside the same process from request to
> request"
>
> I knew that; I was surprised that they did even on a recompilation of
> the script, which the link info doesn't really refer to.

i will see if i can find a good place in the guide to add it and i'll send stas the
patch.

>
>
> *You* have straightened me out, on the other hand.
>
> So, lessee, BEGIN { somevar=somevalue; } ought to work for a variable I
> want reinitialized at compilation only...

i will also add the solution to my guide revisioins.  :-)

>
>
> Yep, works.  Thanks.

--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/



Re: Why do variables not reinitialize when script changed?

Posted by "Keith G. Murphy" <ke...@mindspring.com>.
___cliff rayman___ wrote:
> 
> The perl interpreter has a one global symbol table called the stash where
> all global variables are referenced by package and by variable name.
> Since the interpreter does not go away when a script is recompiled, neither
> does the stash or any of the items contained within it.  Some programmers
> are probably using this as a feature, and therefore it is unlikely that it
> will change.
> This is really standard perl stuff and it has nothing to do with
> Apache::Registry in particular.  It is just something the average perl
> programmer does not come across since we usually load the interpreter, load
> a program, run the program, exit the interpreter.
> 
> check out:
> http://thingy.kcilink.com/modperlguide/porting/Global_Variables_Persistence.html
> 
Thanks for the info and the link.

One note though.  The info in the link really doesn't pertain to my
specific question:

"global variables persist inside the same process from request to
request"

I knew that; I was surprised that they did even on a recompilation of
the script, which the link info doesn't really refer to.

*You* have straightened me out, on the other hand.

So, lessee, BEGIN { somevar=somevalue; } ought to work for a variable I
want reinitialized at compilation only...

Yep, works.  Thanks.

Re: Why do variables not reinitialize when script changed?

Posted by ___cliff rayman___ <cl...@genwax.com>.
The perl interpreter has a one global symbol table called the stash where
all global variables are referenced by package and by variable name.
Since the interpreter does not go away when a script is recompiled, neither
does the stash or any of the items contained within it.  Some programmers
are probably using this as a feature, and therefore it is unlikely that it
will change.
This is really standard perl stuff and it has nothing to do with
Apache::Registry in particular.  It is just something the average perl
programmer does not come across since we usually load the interpreter, load
a program, run the program, exit the interpreter.

check out:
http://thingy.kcilink.com/modperlguide/porting/Global_Variables_Persistence.html

hth,
--
___cliff rayman___cliff@genwax.com___http://www.genwax.com/
"Keith G. Murphy" wrote:

> This is probably a very basic question, understood by everyone but...
>
> Why, when I change a script loaded under Apache::Registry, and the
> script (verifiably) reloads, do global variables not reinitialize?
>
> I'm running Apache 1.3.9, mod_perl 1.21 on a Debian GNU/Linux system.
>
> Am I the only one that finds it odd that the variables hang around
> unchanged when the script that they pertain to is recompiled?
>
> Perhaps this is stated or implied in the documentation; I didn't see it.