[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    Re: mod_perl: How pass variables (objects) from page to page?
From:       John Doe <security.department () tele2 ! ch>
Date:       2005-11-23 10:17:42
Message-ID: 200511231117.42471.security.department () tele2 ! ch
[Download RAW message or body]

Jeremy Nixon am Dienstag, 15. November 2005 23.16:
> John Doe  <security.department@tele2.ch> wrote:
> > Hope it's not a stupid question, but are you sure %d_cache survives a
> > request?  Maybe I'm totally misunderstanding something but I thought
> > after the point
> >
> > } end lexical scope
> >
> > %d_cache gets destroyed (if not still referenced from somewhere else).

Jeremy, all, thanks very much for the replies; I really appreciate it, 
especially since the questions _were_ stupid. 

But nonetheless, it cleared some of my confusion (I think).

It seems that I use closure features from time to time, and from time to time 
I'm totally confused about it. 

> Lexical scope means the scope in which the "thing" is defined in the
> source. So, as far as the handler subroutine is concerned, the %d_cache
> variable never goes out of scope, and is never destroyed.  It makes the
> subroutine into a closure, as someone else pointed out, though it's a
> different usage than you normally see for closures so I didn't think of
> that term to describe it.

Yes :-)
After all the replies I visualize the issue with 3 snippets:

my %d;
sub a { $d{a}++} }

{  
   my %d;
   sub a { $d{a}++} }
}

sub b {
   my %d;
   return sub a { $d{a}++} }
}

> > I would have left out the scope-{} to keep %d_cache at file level.
> > Would that be wrong? And why?
>
> If you put it at the file level it is visible to the entire file.  This
> probably won't hurt, but it is best in general to keep variable scope
> as limited as possible; in this case, it is visible where it is used,
> but not elsewhere.
>
> > Whereas something like
> >
> >    $keep_ref=\%d_cache;
> >
> > in the handler() would, right?
>
> No, "reference" doesn't mean a literal reference, it's used in the English
> sense of simply referring to the variable in the source code.

This hint to the different meanings of 'reference' was very helpful!

Again, thanks a lot to all...
(And: modperl is great! As are all people working on it!)
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic