Boysenberry Payne wrote:
If you worried about @context persisting my @context ought to keep it
local to the scope
@context is declared in unless you register it as a global while
manipulating it.
This is technically true, but confusing. Because the pushcontext() sub
below refers to a variable declared in the enclosing scope, it will keep
a private copy of that variable, and it will persist for the lifetime of
the perl interpreter.
package MyMod1;
my @context = qw( test_mymod1 );
sub pushcontext {
push @context @_;
}
package MyMod2;
my @context = qw( test_mymod2 );
MyMod1::pushcontext( @context );
Ought to end up having each @context being:
MyMod1:: $context[ 0 ] = "test_mymod1"
MyMod1:: $context[ 1 ] = "test_mymod2"
MyMod2:: $context[ 0 ] = "test_mymod2"
Yes, and calling MyMod1::pushcontext() again, even on a later request,
will add to that, putting the new value in $context[2].
- Perrin