Damian Conway writes: : "Bryan C. Warnock" wrote: : > : > No examples are given, but are we to assume that this: : > : > for ($x = 0; $x < 100; $x++) { : > ... : > } : > : > becomes this: : > : > loop $x=0; $x < 100; $x++ { : > ... : > } : : Yes. : : : > How would you use an $x lexically scoped to the loop block? : : You can't...directly. Nor can a C<while> or C<if>. The new rule is that : to be lexical to a block it has to be declared in the block, or in the : block's parameter list. : : You'd need to use another layer of braces: : : do { : loop my $x=0; $x < 100; $x++ { : ... : } : }
In this case, you can get a lexical declarationjust say for 0...100 -> $x { ... } since C<< -> $x >> is considered similar to C<sub ($x)>, which is the only other way to declare a "my" variable outside its block. (In either case, the lexical defaults to read-only within the block.) Note the ... there, borrowed from Ruby to mean "leave out the endpoint". Larry