John Doe <[EMAIL PROTECTED]> 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).
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. > 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. -- Jeremy | [EMAIL PROTECTED]