develooper Front page | perl.perl6.language | Postings from February 2002

Re: proposal: when-blocks, and binding $_

Thread Previous | Thread Next
From:
Allison Randal
Date:
February 26, 2002 14:53
Subject:
Re: proposal: when-blocks, and binding $_
Message ID:
20020226225337.GD1515@shadowed.net
On Tue, Feb 26, 2002 at 02:20:48PM -0800, Brent Dax wrote:
> Austin Hastings:
> #
> # Which, then, would you like:
> #
> # To implicitly localize $_, losing access to an outer version,
> # or to have to change between implicit and explicit operations?

Well, I like the idea of having C<when> and the C<s///> operate on the
same thing. But I don't really want C<when> to either localize or
clobber $_, I want it to leave the information structure alone. That's
why I'd alias $_ at the C<given> or the C<for>, just like I would now.

> # > given $y {
> # > 	when /a/ {...}
> # > 	when /b/ {...}
> # > 	...
> # > }

> 
> That's easy to fix in one of two ways:
> 
> 	for @A -> $y {
> 		for @B -> $x {
			$y =~ s/x/y/;
			$x =~ s/x/y/;
> 			...
> 		}
> 	}

Which gives you no defaults, but the ultimate in clarity and control.

> # for @A {
> #   for @B -> $x {
> #     when /a/ { s/x/y/; }
		s/x/y/;
> #   }
> # }
> #
> # What should that do?

Even if we give C<when> aliasing powers, it is still confusing, because
you jump back and forth between the $_ within the C<when> block and the
$_ between C<when> blocks.

Allison

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About