On Wed, 6 Sep 2000 22:58:05 -0400, John Porter wrote:

>       keys %hash = @things;
>
>is defined as being equivalent to
>
>       @hash{ @things } = ();
>
>This is to support hash-based set operations in a more
>natural way, i.e.
>
>       keys %hash = grep { exists $a{$_} } keys %b;

I have doubts if this would indeed make life simpler. It's a shortcut
for something that is already quite simple, but doing nothing for
slightly more complex situations. In short:

        @hash{@keys} = ();

is the simple case. It can work even if  @keysis not an array, but a
list instead (a grep() expression, for example). These are more complex
but related things:

        @hash{@keys) = 0 .. $#keys;

Try *that* with a list.

Or, coming back to your example: fill a new hash with key/value pairs of
%b with only where intries in %a exist:

        @hash{grep { exists $a{$_} } keys %b} = 
           @b{grep { exists $a{$_} } keys %b};

Ugh.

If you can find a simple alternative syntax for these two, then you have
my blessing.

-- 
        Bart.

Reply via email to