... 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".
In reply to Re: problem with global variables going out of scope
by ikegami
in thread problem with global variables going out of scope
by Kelly Grant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |