Allison Randal writes:
: On Thu, Feb 28, 2002 at 03:17:19PM -0600, Garrett Goebel wrote:
: > I do worry that as Perl grows richer, so does the need for underlying
: > consistency and simplicity. 
: 
: You're not alone in that.
: 
: > I guess it is all about seeking the correct balance. And that is
: > something Larry and the Perl community have a pretty good track record
: > with so far.
: 
: As Damian is so fond of saying, "Trust Larry".

Heh.  Well.  Maybe that works because I don't entirely trust myself.

I should update y'all to my current thinking, which is that $_ is
always identical to the current topic, even if the topic is aliased to
some other variable.  To get at an outer topic, you'd have to use the
same mechanism we'll use for redeclared lexicals:

    my $foo = $OUTER::foo;

    for @x {                    # aliases $_
        for @y -> $y {          # aliases both $x and $_
            print $OUTER::_;
        }
    }

I think this will encourage people not to use $_ for outer loops, which
is a confusing practice.  Use of $_ should generally be reserved for
inner loops.

I expect some people will want a stricture that says you can't use $_
in a lexical scope that aliases the current topic to some other variable.
That is, it would be illegal to say

    for @x {                    # aliases $_
        for @y -> $y {          # aliases both $x and $_
            print $_;           # but this is forbidden
        }
    }

The $_ variable would still be there for operators that want to know
the current topic without knowing its variable name, but you'd have to
refer to it as $y in your program.  Or if you really meant the outer $_,
use $OUTER::_.

I like the simplicity of defining $_ as the current topic, period.  If
there's more than one topic, you should really be using explicit
variable names for clarity.  That's how we do it in natural languages.
We stop talking about "it", and start talking about "this" and "that",
or "A" and "B".

Admittedly, OUTER is kind of klunky, especially if you want to say
$OUTER::OUTER::_.   This klunkiness could be construed as a feature.
Doubtless someone will suggest replacing OUTER:: with a secondary sigil
such as "<" so that you can say something like $<<_ instead.  I'm not
sure that would be an improvement from a readability point of view.
The hiding of outer variable names is not something we want to
encourage in general.

For it, that's now.

Larry

Reply via email to