CraigT wrote:
> Perrin,
> 
> Is what I'm hearing you say is that in the PerlRun environment (and I'm
> guessing the mod_perl environment too), anything that a subroutine uses
> coming from outside that code must be passed as a parameter like
> '&sub($paramter)'.   Am I correct in this.    

Yes and no. The key to understanding this under mod_perl is that global
variables and packaged scoped variables do not get reinitialized for each
request like they do under normal CGI.

So if you are using a global var that should retain state between requests, then
no you don't need to pass it to each subroutine. But if you're not, then yes 
you do.

And btw, you don't need the '&' in front of the the sub.

  sub($paramter)

is the proper way to do it.

> Associating the words scope and closure helped.   I know scope well although
> different languages implement the idea differently.   I had not heard the
> word closure before or had not understood it as scope.

While related, they aren't the same thing. A closure is a function that
"remembers" it's lexical environment when compiled. So it can reference things
that were declared in the same scope as it self.

http://en.wikipedia.org/wiki/Closure_%28computer_science%29
and in Perl
http://www.perl.com/pub/a/2002/05/29/closure.html

Depending on the other languages you know, you might never have encountered a
closure before since they don't exist in languages like C, C++ or Java.

-- 
Michael Peters
Developer
Plus Three, LP

Reply via email to