Mike Lambert asked:
>
> > It's also unnecessary. The Holy Scoping Rules actually work in your favour in
> > this case. In Perl 6 you can just do this:
> >
> >
> > while my $cond = blah() {
> > ...
> > }
> >
> > and C<$cond> is defined *outside* the block.
>
> Question then. Does the following code compile?
>
> while my $i = getNextValue() {
> }
>
> ...
>
> while my $i = getOtherNextValue() {
> }
Yes, it compiles. But you get warnings about two lexical C<$i>'s being
declared in the same scope.
> Does it fail due to scoping $i twice within the same enclosing block, or
> is it sort of like a Scheme/OCaml interpreter where each definition
> creates a scoping for all the lines that follow it, and the second 'my $i'
> merely hides the $i scoped in the 'outer' scope.
The latter. As Perl 5 does now.
And yes, it's annoying.
However, it won;t be an issue in Perl 6. The correct idiom in Perl 6 will
almost certainly be:
while getNextValue() -> $i {
...
}
while getOtherNextValue() -> $i {
...
}
which generates no warning because each C<$i> is a parameter of the
corresponding loop block, and hence scoped to that block.
Damian