You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Demetrios C. Christopher" <dc...@darwinmail.net> on 2000/09/21 02:31:02 UTC

Apache::ASP : perl variables tend to "stick" ...

Hello and thanks in advance for any help.

I am running Apache Stronghold 2.4.2 with modperl 1.21 and Apache::ASP 0.18
(just recently upgraded to the latest - 2.03 I believe - but the problem was
intermittent so I wanted to still check with the forum).  Sure, pretty much
everything could use an update and within the next couple of months I plan
to do so but this software resides on a production box so there's little
room
for mishaps. I am waiting to install all the newest software on a new box
and
then transfer control.

So, as the subject line states, the variables in my .asp's tend to retain
the
values used in previous script runs.  If I leave stronghold going for a
while
without a restart, I can go to one of the forms, load it (initially
everything
should be blank) and then see someone else's info already filled out.  By
the
way, these forms that I wrote (eg. a registration form) are forms that will
initially print out the empty form and then upon submission do data
validations
and reprint the form (prefilling whatever passed the validation).  The same
script handles everything.  I'm sure I didn't invent this but I just wanted
to
make sure everyone got the flow of the code.  No criticism please, this code
works great (prev. an IIS/ASP developer) and it's easy to maintain and
duplicate.  ;)

So, after my scripts take the info from the POST forms and place it into
variables, these variables seem to retain the values instead of clean up at
the
end of the script.  I use "my" throughout.  I simply cannot see why the
variables
would become global _and_ persistent.  I can't vouch for "global" I guess...
I
think it's only within a certain server thread and not the entire server
since
subsequent refreshes may yield other sets of info as well and many refreshes
later you end up cycling through all sets.

Again, I would appreaciate any and all help.

Demetrios


Re: Apache::ASP : perl variables tend to "stick" ...

Posted by Joshua Chamas <jo...@chamas.com>.
"Demetrios C. Christopher" wrote:
> 
> By the way, have you ever considered adding a pre-parsing
> step where you first read in all the subroutines separately
> (say, up to the first line of code) and place them before
> the actual subroutine that will become main and will denote
> the script itself?  That could be a life-saver!  I believe
> that's how the ATG-Dynamo people did it... Dynamo is a Java
> (no booing please) -based app server where the scripts
> (identical to jsp's) are precompiled as their own "classes"
> and then executed.  In their case I believe they do that
> preparsing I mentioned except that in Java I don't think
> it makes much of a difference! Oh well, Perl : 4654574,
> Java : 1 !
> 

I don't think I would be able to successfully parse out
subroutines without writing a complicated parser, but its
an interesting idea.  I could have the UseStrict setting
trigger an error_log warning recommending to move subs 
to a perl library possibly if I find a \nsub\s+\w+\s*{\s*\n 
kind of expression in the ASP perl code.

> I hate to digress again but although I understand the
> "closure" deal, why does it persist?  In one execution I
> understand having that problem of not refreshing the
> value but why in subsequent executions as well?  Shouldn't
> those values disappear by that point?  I had it where I
> was adding elements to an array in the $arr[$#arr] fashion
> and if I pressed the refresh button fast enough the array
> would grow in size by the size of the original array!  I'm
> pretty sure what server thread you're on makes a difference.
> So if you have three threads with the underlined being the
> active one here's what would happen to the array size if I
> added ten elements to $arr by saying $arr[$#arr] = x

The problem/benefit of mod_perl is that things persist so
variables don't get cleared, and my closures don't get 
recompiled.  Your array growing problem sounds like one
that "use strict" programming will take care of because
if you initialize your array with my @arr; then it should
be cleared just fine every script execution.

--Joshua

RE: Apache::ASP : perl variables tend to "stick" ...

Posted by "Demetrios C. Christopher" <dc...@darwinmail.net>.
Thanks Joshua, you're the man.  I haven't tried the solution
but I'm sure it's related.  I wasn't aware of the way the
individual .asp scripts worked (as subroutines that is).
By the way, have you ever considered adding a pre-parsing
step where you first read in all the subroutines separately
(say, up to the first line of code) and place them before
the actual subroutine that will become main and will denote
the script itself?  That could be a life-saver!  I believe
that's how the ATG-Dynamo people did it... Dynamo is a Java
(no booing please) -based app server where the scripts
(identical to jsp's) are precompiled as their own "classes"
and then executed.  In their case I believe they do that
preparsing I mentioned except that in Java I don't think
it makes much of a difference! Oh well, Perl : 4654574,
Java : 1 !

I hate to digress again but although I understand the
"closure" deal, why does it persist?  In one execution I
understand having that problem of not refreshing the
value but why in subsequent executions as well?  Shouldn't
those values disappear by that point?  I had it where I
was adding elements to an array in the $arr[$#arr] fashion
and if I pressed the refresh button fast enough the array
would grow in size by the size of the original array!  I'm
pretty sure what server thread you're on makes a difference.
So if you have three threads with the underlined being the
active one here's what would happen to the array size if I
added ten elements to $arr by saying $arr[$#arr] = x;
_10_ 0 0
10 0 _10_
10 _10_ 10
10 10 _20_
_20_ 10 20

etc, etc.

WEIRD!!!

Anyway, I'll verify "use strict" is turned on although I'm
pretty sure I configured it initially that way.  Moreover
I'll look into extracting one of the forms' subs and putting
them in a perl lib.  If that does it I'll let you know.

Thanks,
Demetrios

-----Original Message-----
From: Joshua Chamas [mailto:joshua@chamas.com]
Sent: Wednesday, September 20, 2000 8:09 PM
To: Demetrios C. Christopher
Cc: modperl@apache.org
Subject: Re: Apache::ASP : perl variables tend to "stick" ...


Oops, sorry for the last send, itchy trigger finger. :)

This variable data caching is a problem common to
Apache::ASP and modperl in general.  "use strict"
programming tends to help, as it requires explicit
variable initialization or declaration.

To do "use strict" for all your Apache::ASP scripts,
turn on the config:

   PerlSetVar UseStrict 1

This is documented at:
  http://www.apache-asp.org/config.html#UseStrict

This problem can also occur with the "my closure"
problem, documented in the mod_perl guide at:
  http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S

To avoid this, I would highly recommend not declaring
subroutines in your ASP scripts, and have those subroutines
in your global.asa or normal perl library.  Apache::ASP
scripts are compiled as perl subroutines, so embeded
subroutines are prone to this behavior.

--Joshua

_________________________________________________________________
Joshua Chamas			        Chamas Enterprises Inc.
NodeWorks >> free web link monitoring	Huntington Beach, CA  USA
http://www.nodeworks.com                1-714-625-4051


"Demetrios C. Christopher" wrote:
>
> Hello and thanks in advance for any help.
>
> I am running Apache Stronghold 2.4.2 with modperl 1.21 and Apache::ASP
0.18
> (just recently upgraded to the latest - 2.03 I believe - but the problem
was
> intermittent so I wanted to still check with the forum).  Sure, pretty
much
> everything could use an update and within the next couple of months I plan
> to do so but this software resides on a production box so there's little
> room
> for mishaps. I am waiting to install all the newest software on a new box
> and
> then transfer control.
>
> So, as the subject line states, the variables in my .asp's tend to retain
> the
> values used in previous script runs.  If I leave stronghold going for a
> while
> without a restart, I can go to one of the forms, load it (initially
> everything
> should be blank) and then see someone else's info already filled out.  By
> the
> way, these forms that I wrote (eg. a registration form) are forms that
will
> initially print out the empty form and then upon submission do data
> validations
> and reprint the form (prefilling whatever passed the validation).  The
same
> script handles everything.  I'm sure I didn't invent this but I just
wanted
> to
> make sure everyone got the flow of the code.  No criticism please, this
code
> works great (prev. an IIS/ASP developer) and it's easy to maintain and
> duplicate.  ;)
>
> So, after my scripts take the info from the POST forms and place it into
> variables, these variables seem to retain the values instead of clean up
at
> the
> end of the script.  I use "my" throughout.  I simply cannot see why the
> variables
> would become global _and_ persistent.  I can't vouch for "global" I
guess...
> I
> think it's only within a certain server thread and not the entire server
> since
> subsequent refreshes may yield other sets of info as well and many
refreshes
> later you end up cycling through all sets.
>
> Again, I would appreaciate any and all help.
>
> Demetrios


Re: Apache::ASP : perl variables tend to "stick" ...

Posted by Joshua Chamas <jo...@chamas.com>.
Oops, sorry for the last send, itchy trigger finger. :)

This variable data caching is a problem common to 
Apache::ASP and modperl in general.  "use strict"
programming tends to help, as it requires explicit
variable initialization or declaration.

To do "use strict" for all your Apache::ASP scripts,
turn on the config:
  
   PerlSetVar UseStrict 1

This is documented at:
  http://www.apache-asp.org/config.html#UseStrict
 
This problem can also occur with the "my closure"
problem, documented in the mod_perl guide at:
  http://perl.apache.org/guide/perl.html#my_Scoped_Variable_in_Nested_S

To avoid this, I would highly recommend not declaring
subroutines in your ASP scripts, and have those subroutines
in your global.asa or normal perl library.  Apache::ASP
scripts are compiled as perl subroutines, so embeded 
subroutines are prone to this behavior.

--Joshua

_________________________________________________________________
Joshua Chamas			        Chamas Enterprises Inc.
NodeWorks >> free web link monitoring	Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051


"Demetrios C. Christopher" wrote:
> 
> Hello and thanks in advance for any help.
> 
> I am running Apache Stronghold 2.4.2 with modperl 1.21 and Apache::ASP 0.18
> (just recently upgraded to the latest - 2.03 I believe - but the problem was
> intermittent so I wanted to still check with the forum).  Sure, pretty much
> everything could use an update and within the next couple of months I plan
> to do so but this software resides on a production box so there's little
> room
> for mishaps. I am waiting to install all the newest software on a new box
> and
> then transfer control.
> 
> So, as the subject line states, the variables in my .asp's tend to retain
> the
> values used in previous script runs.  If I leave stronghold going for a
> while
> without a restart, I can go to one of the forms, load it (initially
> everything
> should be blank) and then see someone else's info already filled out.  By
> the
> way, these forms that I wrote (eg. a registration form) are forms that will
> initially print out the empty form and then upon submission do data
> validations
> and reprint the form (prefilling whatever passed the validation).  The same
> script handles everything.  I'm sure I didn't invent this but I just wanted
> to
> make sure everyone got the flow of the code.  No criticism please, this code
> works great (prev. an IIS/ASP developer) and it's easy to maintain and
> duplicate.  ;)
> 
> So, after my scripts take the info from the POST forms and place it into
> variables, these variables seem to retain the values instead of clean up at
> the
> end of the script.  I use "my" throughout.  I simply cannot see why the
> variables
> would become global _and_ persistent.  I can't vouch for "global" I guess...
> I
> think it's only within a certain server thread and not the entire server
> since
> subsequent refreshes may yield other sets of info as well and many refreshes
> later you end up cycling through all sets.
> 
> Again, I would appreaciate any and all help.
> 
> Demetrios

Re: Apache::ASP : perl variables tend to "stick" ...

Posted by Joshua Chamas <jo...@chamas.com>.

"Demetrios C. Christopher" wrote:
> 
> Hello and thanks in advance for any help.
> 
> I am running Apache Stronghold 2.4.2 with modperl 1.21 and Apache::ASP 0.18
> (just recently upgraded to the latest - 2.03 I believe - but the problem was
> intermittent so I wanted to still check with the forum).  Sure, pretty much
> everything could use an update and within the next couple of months I plan
> to do so but this software resides on a production box so there's little
> room
> for mishaps. I am waiting to install all the newest software on a new box
> and
> then transfer control.
> 
> So, as the subject line states, the variables in my .asp's tend to retain
> the
> values used in previous script runs.  If I leave stronghold going for a
> while
> without a restart, I can go to one of the forms, load it (initially
> everything
> should be blank) and then see someone else's info already filled out.  By
> the
> way, these forms that I wrote (eg. a registration form) are forms that will
> initially print out the empty form and then upon submission do data
> validations
> and reprint the form (prefilling whatever passed the validation).  The same
> script handles everything.  I'm sure I didn't invent this but I just wanted
> to
> make sure everyone got the flow of the code.  No criticism please, this code
> works great (prev. an IIS/ASP developer) and it's easy to maintain and
> duplicate.  ;)
> 
> So, after my scripts take the info from the POST forms and place it into
> variables, these variables seem to retain the values instead of clean up at
> the
> end of the script.  I use "my" throughout.  I simply cannot see why the
> variables
> would become global _and_ persistent.  I can't vouch for "global" I guess...
> I
> think it's only within a certain server thread and not the entire server
> since
> subsequent refreshes may yield other sets of info as well and many refreshes
> later you end up cycling through all sets.
> 
> Again, I would appreaciate any and all help.
> 
> Demetrios

-- 
_________________________________________________________________
Joshua Chamas			        Chamas Enterprises Inc.
NodeWorks >> free web link monitoring	Huntington Beach, CA  USA 
http://www.nodeworks.com                1-714-625-4051