In a nutshell, the old Perl 5 syntax is
but with the proposed Perl 6 syntax:if (my $result = expensive_function()) { # $result is in scope here } # $result no longer in scope
This is really enforcing the rule that a variables scope is where it was defined.if (my $result = expensive_function()) { # $result is in scope here } # $result is also in scope here !!
I imgine that there is an exception in Perl 5 so that in this case, $result is scoped only within the control structure rather that in the scope in which it was defined, outside the control structure.
The scoping exception that is described regarding a subroutine defition is a red herring because a sub is not part of logic flow, it's part of the program definition. I can't think of any programming language where variables defined as part of a subroutine call would continue to live after the subroutine goes out of scope.
To put it another way, variables defined by an object's instantiation are not available to the rest of the objects just because they're 'a brace away' -- those variables only exist within that object, unless there are accessor methods available for public consumption.
--t. alex
"Of course, you realize that this means war." -- Bugs Bunny.
|
---|