On 8 Sep 2000 04:57:46 -0000, Perl6 RFC Librarian wrote:

>Instead of
>
>       %subhash = map { f($_) ? ($_, $hash{$_}) : () } keys %hash;     # lengthy
>
>one may now write
>
>       %subhash = %hash{f($_)};        # code block f($_) will be evaluated for Truth 
>over all the keys

I almost liked that one.

I like what it produces: a hash slice that contains not only the values,
but the keys and the values, interleaved.

But I do not like the built-in grep.

I would prefer this syntax:

        %extract = %hash{@keys};

which is like:

        %extract = map { $_ => $hash{$_} } @keys;

It's more in sync with current perl:

        @values = @hash{@keys};

which returns a list of (just the) hash values.

If you want the grep, you can use it explicitely:

        %extract = %hash{ grep f($_), keys %hash };

-- 
        Bart.

Reply via email to