On Tue, May 26, 2009 at 06:43:40PM -0500, John M. Dlugosz wrote:
> Daniel Carrera daniel.carrera-at-theingots.org |Perl 6| wrote:
>> The following construction doesn't do what a user might expect:
>>
>> for [email protected] -> $k { do_something($k,@foo[$k]) }
>
> Write ^[email protected] as a shortcut of [email protected], which is the
> variation to exclude that endpoint if you would rather not write
> [email protected].

An even cleaner shortcut might be to use ^...@foo instead of ^[email protected]:

    for ^...@foo -> $k { do_something($k, @foo[$k]) }

Somewhat clearer could be:

    for @foo.keys -> $k { do_something($k, @foo[$k]) }

And some may prefer:

    for @foo.kv -> $k, $v { do_something($k, $v) }

I think the anti-pattern of "[email protected]" (or its incorrect
form "[email protected]") should probably disappear in favor of
the above forms instead.

Pm

Reply via email to