in reply to Re: Re: How can I add the values of a hash?
in thread How can I add the values of a hash?

I still don't get it. That code snippet sets the hash entry at $k to two times what's in $value. It still seems to me that you're not seeing that you can use a += operator on a hash element. What am I missing?

foreach (@temp) { my ($instan, $value) = (split /\*/, $_); my $k = $key . ":" . $instan; $DM_D{$k} += $value; # Change this line maybe??? }

Replies are listed 'Best First'.
Re: Re: Re: Re: How can I add the values of a hash?
by OM_Zen (Scribe) on Feb 08, 2003 at 17:36 UTC
    Hi ,

    eval { my $values_accrued = join "+",@hash{keys %hash};print + "[$values_accrued]\n"; }


    You can do this to accrue the values of the hash and store it to a scalar variable if that is what you need to have for the value of the addendum of the values of the hash itself .(The code is untested ,just try out and say ,I am in a friend's place with no perl in his computer ,(Hey would this work ) shall go home and test it)