On Fri, Oct 05, 2001 at 11:58:50AM -0400, Bill Jones wrote:
> {
>     my $var = 100;
>     print "\$var is $var\n";
> 
> }
> 
>     print "But here \$var is $var\n";
> 
> 
> How can I or is there a way to get outer $var to be equal to 100 without
> making $var global?

It depends on what you mean by global.  If you declare the variable in the
same scope, e.g.

    my $var;
    {
        $var = 100;
        print "$var\n";
    }

    print "$var\n";

$var will be 100 both times.  Otherwise, no, there is no such way for an
outer scope to gain access to the variables in a nested scope.


> Also, you're not allowed to set it to 100 outside of the anonymous sub
> either.

Sure you are, you just have to declare the variable outside of the anonymous
sub.

By the way, there is no anonymous sub in your example.  Are you pulling the
anonymous sub thing out of thin air, or did you think the bare block was an
anonymous sub?


What is it you're trying to accomplish with this?  Generally speaking, if
there is a desire to gain access to a nested scope's variables it's a sign
that you need to redesign.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to