On Tue, May 18, 2004 at 11:14:30PM +0200, Stéphane Payrard wrote:
> I thought overloading the += operator
> 
>    %a += @a;

There's been lots of discussion of this, but:

> Probably that operator should be smart enough to be fed with
> a mixed list of array and hashes as well:
> 
>   %a += ( @a, %h);  #  would mean %a += ( @a, keys %h)

I would like this sort of "addition" of hashes to allow
for two meanings.  A counting hash can be used for testing
whether a key exists, but also for how many times it
has occurred.

So (in Perl 5):

    add( %a, %b )

could work with:

    ++$a{$_} for keys %b

only if you are only interested in existance, but it should
work as:

    while( my($k,$v) = each %b ) {
        $a{$k} += $v;
    }

so that you can merge one set of counts into another.
In Perl 6, this could be a function (perhaps wrapped in
an operator, I'm not especially concerned about that)
that runs through its list of "keys" and increments the
ones that are scalar, but for pairs it increments the key
by the value.

-- 

Reply via email to