On Mon, Jan 21, 2002 at 03:02:06PM -0500, Tzadik Vanderhoof wrote:
> Why all the fuss?  Often, you would *want* to access that lexical after the
> loop terminates, for instance to check how it terminated.

In most cases you don't want that to happen, usually the life of the
lexical is only the block.  If you do want it to live on you can
simply predeclare it.

    my $foo;
    if $foo = bar {
        ...
    }

which is much simpler than the current setup, where you'll often have
to do this to keep $foo in its proper place.

    do {
        if my $foo = bar {
            ...
        }
    }

The problem with having lexicals leaking out of loop/if conditions
is it defeats the point of lexicals!  Currently, if you write:

    use strict;
    if( my $bar = bar() ) {
        ..
    }

    $bar = baz();  # ooops, ment $baz

you'll get an error from that typo.  Under the current setup:

    use strict;
    if my $bar = bar() {
        ...
    }

    $bar = baz();   # just fine, since it was declared above.

no error.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <[EMAIL PROTECTED]>         Kwalitee Is Job One
Fuck with me and I will saw off your legs.
        http://www.unamerican.com/

Reply via email to