On Tue, 2002-03-26 at 13:19, Larry Wall wrote: > Aaron Sherman writes: > : Ok, so am I to take it that you could say: > : > : FOO: for @x { > : BAR: for @y { > : print $FOO::_; > : } > : } > > Er, I don't think so. > > : Or is OUTER a special-case label? > > It's a special case like MY::, and somewhat ugly to discourage you from > using it when you should probably be naming your loop variables.
That's too bad. If OUTER could only jump up one level, it's going to be painful. For example, when you take your example, and go back to modify the code. It may not be glaringly obvious that adding a middle loop will cause the code to break. We're treading dangerously close to putting TCL's upvar into Perl, which would be a crime against God and man. However, I think you can have a reasonable syntax for what you want. Use labels as namespaces via a special syntax. Then, scope labels lexically (already the case?), so you can't use this syntax to get at callers' namespaces, etc. Here's an example syntax: FOO: for @x { BAR: for @y { my $foo_under FOO:= $_; print $_, $foo_under; } } This takes visual advantage of ":=" as the aliasing syntax while maintaining the look of a label. Of course, that's just one syntax possibility. The concept here is accessing lexically-scoped namespaces via labels. Given this, you cannot break the code by adding a middle loop, and it's obvious exactly what was intended. The other syntax you could use would be less generic, but would really nail home the idea of topic to the programmer: FOO: for @x { BAR: for @y { my $foo_under is topicof(FOO); print $_, $foo_under; } } I don't like this as much, but I see the benefits. > : Personally, I've always prefered this syntax: > : > : for @x {----\ > : for @y { | > : print;<-/ > : } > : } > : > : Which is visually appealing and raises coding style arguments to a whole > : new level. > > Hmm, tempting. Ok, I'll get right on ascii_art_toke.c. I thought I'd never get a chance to bring machine vision into the Perl core! ;-)