Nathan Wiger <[EMAIL PROTECTED]> writes:

> > How usable is this ?
> > 
> > I may be missing something, but if every variable mentioned in an anonymous
> > block is assumed to be declared with my, then how do you access or modify
> > the value of any variable outside the block ?
> >
> > Graham.
> 
> I knew someone was going to ask this; after I sent it I realized I
> should have included an example.
> 
> 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

This example scares me.  It means that every time I add a `my' or an
`our' line to my program, to add another local variable (sorry,
fluid-let should *really* be called `now'), I have to run along the
entire program and see if I happened to use that variable name
somewhere else, expecting it to be local to that block.  Will this
also apply to `use scope 'subs''?

I, for one, will *never* use such a construct.  It provides the user
with the dangers of `no strict' combined with the illusion of safety
of `use strict'.  

> 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).

Only you must make *very* sure that the variable name you're using in
your block is used *nowhere* else.  So it's every bit as bad as using
a global variable -- the name must be unique.

-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | [EMAIL PROTECTED]
Compugen Ltd.          |Tel: +972-2-6795059 (Jerusalem) \ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658514 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels

Reply via email to