On Sun, 10 Jun 2001, Charles Lu wrote:
> When I run the following code with the Warning flag I get the following
> message:
>
> Variable "%hash" will not stay shared....
This can be a dangerous situation. Perl is complaining because
of the nested subroutine. The dangerous part is that it that the
value of %hash may be diffrent for the inner subroutine than the
outer subroutine due to Perls dynamic scoping. Run your program
with "use Diagnostics" for more information on vague error
messages. It's great.
What you need to do is use an anonymous subroutine for the inner
routine like this...
my $by_value = sub {
...and call it like this...
&$by_value
Or you could take the whole nested subroutine and put it into
a package and include it with use. Making simple packages
out of subroutine groups like this is actually pretty easy and
my favortie way of making static variables, which is what you
seem to be wanting here.
--
Ian