in reply to Re^9: OUR declaration
in thread OUR declaration

Who said anything about making $q a global? It already was. I'm saying he might have wanted it to keep on being a global. When fixing someone else's code, I try to follow the "minimal change" doctrine. If it's a global, leave it a global. Especially since it's proper for this variable to be a global, given how it's used for input, processing and output.

I'm still confused why you say "Lexical variables don't retain values when they go out of scope". It's true, but it's meaningless here. Both lexical variables and localized package variables lose their values at the end of their scope. Both global lexical variables and global package variables have the same scope. Replacing my $q with local our $q would give $q neither a larger scope nor a greater persistance. Do you think otherwise?

Replies are listed 'Best First'.
Re^11: OUR declaration
by perrin (Chancellor) on Sep 25, 2006 at 17:49 UTC
    The scope of a localized package variable variable is not really the same as a lexical, and the existence of that variable is persistent in a way that a lexical is not, even if the value becomes undefined. That's not really the point though. The point is that this is a bad solution. Changing the code so that subs are called with the variables they need (providing isolation they don't have when used with globals) is a good solution. Bad "quick fix" solutions should not be encouraged. Think of the poor guy who comes across this code next and how his eyes will bug out at the "local our" junk.