On Tue, 08 Aug 2000, Nathan Wiger wrote:
> There's two ways I see it:
>
> 1) do {} block
>
> $val = do {
> $x = 10;
> # ... stuff happens ...
> $y;
> };
>
> In which case $val = $y.
>
> 2) explicit our() scoping
>
> $x = 10;
> our $y = 10;
> {
> $x = 5; # auto-my'ed
> $y += $x; # $y already our'ed above
> }
> print "$y"; # 15
>
> Remember, you can still override the scopes I propose with an explicit
> my or our. Admittedly, 'blocks' is not nearly as big a benefit as 'subs'
> is, but has some applications, particularly if you're a "likes anonymous
> blocks" kind of person (which some people are).
This could lead to some ugly problems down the road.
You have the following block, with your above rules:
while($x)
{
$y += foo($x);
$x = bar($x);
$big_global_variable = analyze($y,$x);
}
This leaves you with three variables that may or may not be dependent
on the upper scope for resolution by default.
As written, $y, for instance, is local to the while loop, and is reset
on every iteration.
But, you could add a completely independent $y outside, (my, our, or
global), that then changes the context of $y inside the loop, which you
didn't even look at, and this is bad.
Compare to the old rules, where every variable is *always* dependent
on the upper scope, unless it's explicitly ignoring the upper scope.
While its true you can suffer a similar fate by supplanting a global
variable with a lexical variable in an intermediate scope, you're not
changing the scope context of the lower-level variables.
It's one thing to call a wrong number. It's another when the phone
company changes your number for you.
--
Bryan C. Warnock
([EMAIL PROTECTED])