On Fri, 5 Oct 2001, Bill Jones wrote:

> Given -
>
> {
>     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?  Also, you're not allowed to set it to 100 outside of
> the anonymous sub either.

The $var inside the { } is lexically scoped to that block, and cannot be
seen outside of it.  If you want both a $var inside the scope and one
outside the scope, you should declare the one inside the scope with
'local' (intead of with 'my'), so it doesn't tromp over the global $var.
But they are still two distinct variables.

-- Brett
                                          http://www.chapelperilous.net/
------------------------------------------------------------------------
There's a way out of any cage.
                -- Captain Christopher Pike, "The Menagerie" ("The Cage"),
                   stardate unknown.


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

Reply via email to