>
In general you should not declare subroutines inside ASP pages.


*WHAT*????????  Whyever NOT?  Subroutines are.... like one of my most
basically consistent ways of subdividing programs.  I use them
extensively!


Consider that Apache::ASP scripts are compiled as subroutines. Generally one does not defined subroutines in subroutines, you can, but it can easily create closure issues like the one you encountered.

IF you really need to defined a subroutine in a script, define it as
an anonymous sub, like

my $sub = sub { ... };
&$sub(); # execute sub

This way it will be redefined each script invocation and will be immune
to the my() closure caching effect that nested subs can create.  Better yet,
if you have common subs that you want to share between scripts, put them
into the global.asa file, which is the default package for your scripts.


(However, I have the rather faint memory that the newest version of
Apache::ASP presents a workaround... others will probably comment on this.)


Yes, the last version of Apache::ASP tries to detect the use of named subs in scripts, and if it finds them, will turn off script compilation caching.


I never found any issue with it, outside of occaisonal "redefined subroutine" errors in the logs if I had two scripts with the same subroutine name...



This issue that you have run into is an important reason for not defining subs in scripts. Another is that since all scripts are defined in the same perl package ( aka. GlobalPackage config ), the named subs will be shared between scripts, and could create a conflict if scripts name subs the same.

If you really want to have named subs in your scripts, consider setting
NoCache, which will prevent your scripts from being cached so that
the my() closure caching won't affect you.

Regards,

Josh

________________________________________________________________
Josh Chamas, Founder                   phone:925-552-0128
Chamas Enterprises Inc.                http://www.chamas.com
NodeWorks Link Checker                 http://www.nodeworks.com


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to