On Tue, Aug 08, 2000 at 02:37:54PM -0000, Perl6 RFC Librarian wrote:

> =head3 blocks
> 
> The C<blocks> scoping pragma automatically scopes variables to the
> innermost B<anonymous> block. The key work here is anonymous. The main
> program itself is seen as the outermost block. So, this code:
> 
>    $x = 10;
>    {
>       $x = 5;
>    }
>    if ($x == 10) {
>       $x = 25;
>    }
>    print "$x\n";
> 
> Would result in "25" being printed out. Here's why:
> 
>    1. The C<$x = 10> is automatically scoped with its own C<my>.
> 
>    2. The C<$x = 5> inside the B<anonymous> block is automatically
>       scoped with its own C<my>.
> 
>    3. The C<$x = 25> code, however, inside the C<if> statement
>       is not scoped, since it is not an B<anonymous> block. Since
>       there is already an C<$x> in the current block, there is
>       no need to rescope it.

How usable is this ?

I may be missing something, but if every variable mentioned in an anonymous
block is assumed to be declared with my, then how do you access or modify
the value of any variable outside the block ?

Graham.

Reply via email to