in reply to problem with global variables going out of scope
... my $showPUV = 0; ... sub FilterMessage { ... our $showPUV; ...
Those are two different variables! The first is a lexical (my) variable, scoped to the file. The second is an alias to the package (our) variable $main::showPUV.
Solution 1
my $showPUV = 0; sub FilterMessage { ... if ( $showPUV ... ...
Noone outside of this file can access $showPUV. FilterMessage can since it's in the same file, even if it's called from another file.
Solution 2
our $showPUV = 0; sub FilterMessage { ... if ( $showPUV ... ...
Everyone can access $showPUV (altough other packages must use $main::showPUV). our $showPUV; is optional in FilterMessage, because the one at the top level is still in scope.
Update: Clarified by adding "an alias to".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: problem with global variables going out of scope
by acid06 (Friar) on Mar 28, 2006 at 21:12 UTC | |
by ikegami (Patriarch) on Mar 28, 2006 at 22:07 UTC | |
by acid06 (Friar) on Mar 29, 2006 at 00:15 UTC |