Graham Barr said:
> > 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.
>

> 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 ?

Yes, seems like we need a way to import globally scoped variables into the
block, if this were to be accepted.

In PHP, for example (see
http://php.net/manual/html/language.variables.scope.html) all variables are
considered local to their block, unless imported into a block with the
"global" keyword. I absolutely hate this though.

--Michael


Reply via email to