> 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() {
}

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.

This happens a lot in C where some compilers scope the initializer in a
for loop to the enclosed loop (CodeWarrior), and some scope it in the
enclosing block (GCC, MSVC). The latter approach causes people to write:
for(int i=0; ... ) { ... }
for(i=0; ... ) { ... }

Which of course breaks when you remove the first loop. I always found that
annoying...and that's what the following was used for, in those compilers:
#define for if(0) {} else for

Mike Lambert

Reply via email to