The when keyword can use a localizer that makes its target obvious but
slightly counter-intuitive.
given $x {
when /a/ { ... }
}
The problem is operations within the when-block that might expect to
use $_, the defaultdefault variable.
given $x {
when /a/ { s/a/A/; }
}
After all, I used a default-match in the when-expr, so why not keep
using it?
Three possible truths:
Possibility Z- when-blocks do nothing (currently).
for @A
{
for @B -> $x
{
when /b/ # m// checks localized $x from @B
{
s/b/bee/; # changes $_ from @A.
print; # prints $_ from @A.
}
}
}
Possibility A- when-blocks "localize" $_ inside.
for @A
{
for @B -> $x
{
when /b/ # m// checks localized $x from @B
{ # Implicit: local $_ = $x;
s/b/bee/; # s/// works on $_ which is now = $x.
print; # prints $_ from @B
}
}
}
Possibility B- when-blocks accept a -> operator, which if used "naked"
binds the current localizer to $_.
for @A
{
for @B -> $x
{
when /b/ -> # m// checks localized $x from @B
{ # unadorned -> means "$x -> $_"
s/b/bee/; # s/// affects $x, from @B
print; # prints $x via $_
}
when /ever/ # m// checks localized $x from @B
{ # no -> means no binding, $_ is from @A
s/b/bee/; # s/// works on $_, from @A.
print; # prints $_, from @A.
}
}
}
I prefer B, because it allows control over whether or not I want to
'hide' $_ inside the when-block.
=Austin
__________________________________________________
Do You Yahoo!?
Yahoo! Greetings - Send FREE e-cards for every occasion!
http://greetings.yahoo.com