goehle has asked for the wisdom of the Perl Monks concerning the following question:

I'm sure that this is a fairly simple question, but its still giving me fits. How do you share variables when using Safe? There isn't a lot of documentation on Safe.pm and I can't seem to figure this out. The following code *should* print 7 when its run. Instead it doesn't print anything.

use Safe; my $maxCounter = 7; my $testCode = 'return $maxCounter;'; my $container = new Safe; $container -> share('$maxCounter'); print $container->reval($testCode)."\n";

Replies are listed 'Best First'.
Re: Safe and sharing variables
by goehle (Novice) on May 15, 2012 at 14:13 UTC
    Nevermind... Of course I figure it out 20 seconds after I post. The "my $maxCounter" needs to be "our $maxCounter" in order for you to be able to share. (Because share behaves like export).